Решение на Трета задача от Константин Тодоров

Обратно към всички решения

Към профила на Константин Тодоров

Резултати

  • 3 точки от тестове
  • 0 бонус точки
  • 3 точки общо
  • 24 успешни тест(а)
  • 20 неуспешни тест(а)

Код

module RBFS
end
class RBFS::File
attr_accessor :data
def initialize(object = nil, file_type = nil)
@data = object
@type = file_type.to_sym if file_type != nil
set_type
end
def data_type
@type
end
def set_type
@type = :nil if @data == nil
@type = :string if @data.is_a? String
@type = :symbol if @data.is_a? Symbol
@type = :number if @data.is_a? Integer or @data.is_a? Float
@type = :boolean if !!@data == @data
end
def serialize
@type.to_s + ":" + @data.to_s
end
def self.parse(string_data)
split_data = string_data.split(":")
content = split_data[1]
if split_data.size > 2
content += ":" + split_data[2...split_data.size].join(":")
end
RBFS::File.new content, split_data[0]
end
end
class RBFS::Directory
attr_reader :files
attr_reader :directories
def initialize
@files = {}
@directories = {}
end
def add_file(name, file)
@files[name] = file
end
def add_directory(name, directory = RBFS::Directory.new)
@directories[name] = directory
end
def [](name)
return @directories[name] if @directories.include? name
return @files[name] if @files.include? name
nil
end
def serialize
serialized_string = @files.size.to_s + ":" + get_serialized_string
serialized_string += @directories.size.to_s + ":"
@directories.each do |name, directory|
serialized_string << name + ":" + directory.serialize.size.to_s
serialized_string << ":" + directory.serialize
end
serialized_string
end
def get_serialized_string
serialized_string = ""
@files.each do |name, file|
serialized_string += name + ":" + file.serialize.length.to_s + ":" + file.serialize
end
serialized_string
end
def self.parse(string_data)
return RBFS::Directory.new if string_data == nil
dir = RBFS::Serialize.parse_information string_data
dir
end
end
class RBFS::Serialize
@dir = RBFS::Directory.new
def self.parse_information(string_data)
split_data = string_data.split(":")
temp_count, data_size = RBFS::Serialize.parse_file_info split_data
RBFS::Serialize.parse_dir_info split_data, temp_count, data_size
@dir
end
def self.parse_file_info(split_arr, cur_file = 0, counter = 1, file_size = 0)
return if cur_file == split_arr[0].to_i # number of files
file = RBFS::Serialize.split_file_info split_arr, counter, file_size
@dir.add_file file["name"], RBFS::File.parse(file["data"])
counter += 3
cur_file += 1
r2, r3 = RBFS::Serialize.parse_file_info split_arr, cur_file, counter, file["size"]
counter, file_size = counter + r2, file_size + r3 unless r2 == nil and r3 == nil
return counter, file_size
end
def self.split_file_info(split_arr, counter, size)
data = split_arr[counter - 1] + ":" + split_arr[counter]
name = data.slice(size..data.length)
name = split_arr[counter] if counter == 1
size = split_arr[counter + 1].to_i
res_data = (split_arr[counter + 2] + ":" + split_arr[counter + 3]).slice(0...size)
return { "name" => name, "data" => res_data, "size" => size }
end
def self.parse_dir_info(split_arr, counter, file_size, dir_counter = 0)
dir_info = RBFS::Serialize.split_directory_info split_arr, counter, file_size
dir_name = split_arr[counter - 3].to_s
@dir.add_directory dir_name, RBFS::Directory.new if dir_info["count"] == 0
return if dir_counter == dir_info["count"]
@dir.add_directory dir_info["name"], RBFS::Directory.parse(temp_dir_data)
counter += 3
dir_counter += 1
RBFS::Serialize.parse_dir_info(dir, split_arr, counter, file_size, dir_counter)
end
def self.split_directory_info(split_array, counter, file_size)
name = split_array[counter + 1].to_s
data = split_array[counter - 1].to_s + ":" + split_array[counter].to_s
count = data.slice(file_size..data.length).to_i
data_size = split_array[counter + 1].to_s.to_i
dir_data = split_array[counter + 2].to_s.slice(0, data_size)
dir_data = nil if data_size == 0
return { "name" => name, "data" => data, "count" => count,
"data_size" => data_size, "dir_data" => dir_data }
end
end

Лог от изпълнението

..........F.FF...........FF..FFFFFFFFFFFFFFF

Failures:

  1) RBFS Directory serialization ::parse can parse empty directories
     Failure/Error: parsed_directory = RBFS::Directory.parse('0:0:')
     NoMethodError:
       undefined method `+' for nil:NilClass
     # /tmp/d20141111-26053-13662oz/solution.rb:136:in `split_directory_info'
     # /tmp/d20141111-26053-13662oz/solution.rb:123:in `parse_dir_info'
     # /tmp/d20141111-26053-13662oz/solution.rb:94:in `parse_information'
     # /tmp/d20141111-26053-13662oz/solution.rb:83:in `parse'
     # /tmp/d20141111-26053-13662oz/spec.rb:101:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) RBFS Directory serialization ::parse can parse directory trees without files
     Failure/Error: parsed_directory = RBFS::Directory.parse('0:2:dir1:15:0:1:dir2:4:0:0:dir3:4:0:0:')
     NoMethodError:
       undefined method `+' for nil:NilClass
     # /tmp/d20141111-26053-13662oz/solution.rb:136:in `split_directory_info'
     # /tmp/d20141111-26053-13662oz/solution.rb:123:in `parse_dir_info'
     # /tmp/d20141111-26053-13662oz/solution.rb:94:in `parse_information'
     # /tmp/d20141111-26053-13662oz/solution.rb:83:in `parse'
     # /tmp/d20141111-26053-13662oz/spec.rb:117:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  3) RBFS Directory serialization ::parse can parse directories recursively
     Failure/Error: expect(rbfs_directory['solution.rb'].data ).to eq :hidden
     NoMethodError:
       undefined method `data' for nil:NilClass
     # /tmp/d20141111-26053-13662oz/spec.rb:133:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  4) RBFS File data type string can be detected
     Failure/Error: expect(file.data_type).to eq :string
       
       expected: :string
            got: :nil
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,2 @@
       -:string
       +:nil
     # /tmp/d20141111-26053-13662oz/spec.rb:240:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  5) RBFS File data type string can be serialized
     Failure/Error: expect(file.serialize).to eq 'string:Hi'
       
       expected: "string:Hi"
            got: "nil:Hi"
       
       (compared using ==)
     # /tmp/d20141111-26053-13662oz/spec.rb:244:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  6) RBFS File data type symbol can be detected
     Failure/Error: expect(file.data_type).to eq :symbol
       
       expected: :symbol
            got: :nil
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,2 @@
       -:symbol
       +:nil
     # /tmp/d20141111-26053-13662oz/spec.rb:266:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  7) RBFS File data type symbol can be serialized
     Failure/Error: expect(file.serialize).to eq 'symbol:yo'
       
       expected: "symbol:yo"
            got: "nil:yo"
       
       (compared using ==)
     # /tmp/d20141111-26053-13662oz/spec.rb:270:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  8) RBFS File data type symbol can be parsed
     Failure/Error: expect(file.data     ).to eq :hello
       
       expected: :hello
            got: "hello"
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,2 @@
       -:hello
       +"hello"
     # /tmp/d20141111-26053-13662oz/spec.rb:276:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  9) RBFS File data type number can be detected
     Failure/Error: expect(file.data_type).to eq :number
       
       expected: :number
            got: :nil
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,2 @@
       -:number
       +:nil
     # /tmp/d20141111-26053-13662oz/spec.rb:285:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  10) RBFS File data type number can be serialized
     Failure/Error: expect(file.serialize).to eq 'number:666'
       
       expected: "number:666"
            got: "nil:666"
       
       (compared using ==)
     # /tmp/d20141111-26053-13662oz/spec.rb:289:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  11) RBFS File data type number can be parsed
     Failure/Error: expect(file.data     ).to eq 1234
       
       expected: 1234
            got: "1234"
       
       (compared using ==)
     # /tmp/d20141111-26053-13662oz/spec.rb:295:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  12) RBFS File data type float number can be detected
     Failure/Error: expect(file.data_type).to eq :number
       
       expected: :number
            got: :nil
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,2 @@
       -:number
       +:nil
     # /tmp/d20141111-26053-13662oz/spec.rb:304:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  13) RBFS File data type float number can be serialized
     Failure/Error: expect(file.serialize).to eq 'number:666.6'
       
       expected: "number:666.6"
            got: "nil:666.6"
       
       (compared using ==)
     # /tmp/d20141111-26053-13662oz/spec.rb:308:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  14) RBFS File data type float number can be parsed
     Failure/Error: expect(file.data     ).to eq 3.14
       
       expected: 3.14
            got: "3.14"
       
       (compared using ==)
     # /tmp/d20141111-26053-13662oz/spec.rb:314:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  15) RBFS File data type boolean true can be detected
     Failure/Error: expect(file.data_type).to eq :boolean
       
       expected: :boolean
            got: :nil
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,2 @@
       -:boolean
       +:nil
     # /tmp/d20141111-26053-13662oz/spec.rb:323:in `block (6 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  16) RBFS File data type boolean true can be serialized
     Failure/Error: expect(file.serialize).to eq 'boolean:true'
       
       expected: "boolean:true"
            got: "nil:true"
       
       (compared using ==)
     # /tmp/d20141111-26053-13662oz/spec.rb:328:in `block (6 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  17) RBFS File data type boolean true can be parsed
     Failure/Error: expect(file.data     ).to eq true
       
       expected: true
            got: "true"
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,2 @@
       -true
       +"true"
     # /tmp/d20141111-26053-13662oz/spec.rb:334:in `block (6 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  18) RBFS File data type boolean false can be detected
     Failure/Error: expect(file.data_type).to eq :boolean
       
       expected: :boolean
            got: :nil
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,2 @@
       -:boolean
       +:nil
     # /tmp/d20141111-26053-13662oz/spec.rb:342:in `block (6 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  19) RBFS File data type boolean false can be serialized
     Failure/Error: expect(file.serialize).to eq 'boolean:false'
       
       expected: "boolean:false"
            got: "nil:false"
       
       (compared using ==)
     # /tmp/d20141111-26053-13662oz/spec.rb:347:in `block (6 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  20) RBFS File data type boolean false can be parsed
     Failure/Error: expect(file.data     ).to eq false
       
       expected: false
            got: "false"
       
       (compared using ==)
     # /tmp/d20141111-26053-13662oz/spec.rb:353:in `block (6 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.04828 seconds
44 examples, 20 failures

Failed examples:

rspec /tmp/d20141111-26053-13662oz/spec.rb:100 # RBFS Directory serialization ::parse can parse empty directories
rspec /tmp/d20141111-26053-13662oz/spec.rb:116 # RBFS Directory serialization ::parse can parse directory trees without files
rspec /tmp/d20141111-26053-13662oz/spec.rb:124 # RBFS Directory serialization ::parse can parse directories recursively
rspec /tmp/d20141111-26053-13662oz/spec.rb:239 # RBFS File data type string can be detected
rspec /tmp/d20141111-26053-13662oz/spec.rb:243 # RBFS File data type string can be serialized
rspec /tmp/d20141111-26053-13662oz/spec.rb:265 # RBFS File data type symbol can be detected
rspec /tmp/d20141111-26053-13662oz/spec.rb:269 # RBFS File data type symbol can be serialized
rspec /tmp/d20141111-26053-13662oz/spec.rb:273 # RBFS File data type symbol can be parsed
rspec /tmp/d20141111-26053-13662oz/spec.rb:284 # RBFS File data type number can be detected
rspec /tmp/d20141111-26053-13662oz/spec.rb:288 # RBFS File data type number can be serialized
rspec /tmp/d20141111-26053-13662oz/spec.rb:292 # RBFS File data type number can be parsed
rspec /tmp/d20141111-26053-13662oz/spec.rb:303 # RBFS File data type float number can be detected
rspec /tmp/d20141111-26053-13662oz/spec.rb:307 # RBFS File data type float number can be serialized
rspec /tmp/d20141111-26053-13662oz/spec.rb:311 # RBFS File data type float number can be parsed
rspec /tmp/d20141111-26053-13662oz/spec.rb:321 # RBFS File data type boolean true can be detected
rspec /tmp/d20141111-26053-13662oz/spec.rb:326 # RBFS File data type boolean true can be serialized
rspec /tmp/d20141111-26053-13662oz/spec.rb:331 # RBFS File data type boolean true can be parsed
rspec /tmp/d20141111-26053-13662oz/spec.rb:340 # RBFS File data type boolean false can be detected
rspec /tmp/d20141111-26053-13662oz/spec.rb:345 # RBFS File data type boolean false can be serialized
rspec /tmp/d20141111-26053-13662oz/spec.rb:350 # RBFS File data type boolean false can be parsed

История (2 версии и 0 коментара)

Константин обнови решението на 06.11.2014 23:05 (преди над 9 години)

+module RBFS
+
+end
+
+class RBFS::File
+ attr_accessor :data
+
+ def initialize(object = nil, file_type = nil)
+ @data = object
+ @type = file_type.to_sym if file_type != nil
+ set_type
+ end
+
+ def data_type
+ @type
+ end
+
+ def set_type
+ @type = :nil if @data == nil
+ @type = :string if @data.is_a? String
+ @type = :symbol if @data.is_a? Symbol
+ @type = :number if @data.is_a? Integer or @data.is_a? Float
+ @type = :boolean if !!@data == @data
+ end
+
+ def serialize
+ @type.to_s + ":" + @data.to_s
+ end
+
+ def self.parse(string_data)
+ RBFS::File.new string_data.split(":")[1], string_data.split(":")[0]
+ end
+end
+
+class RBFS::Directory
+ attr_reader :files
+ attr_reader :directories
+
+ def initialize
+ @files = {}
+ @directories = {}
+ end
+
+ def add_file(name, file)
+ @files[name] = file
+ end
+
+ def add_directory(name, directory = RBFS::Directory.new)
+ @directories[name] = directory
+ end
+
+ def [](name)
+ return @directories[name] if @directories.include? name
+ return @files[name] if @files.include? name
+ nil
+ end
+
+ def serialize
+ serialized_string = @files.size.to_s + ":" + get_serialized_string
+ serialized_string += @directories.size.to_s + ":"
+ @directories.each do |name, directory|
+ serialized_string << name + ":" + directory.serialize.size.to_s
+ serialized_string << ":" + directory.serialize
+ end
+ serialized_string
+ end
+
+ def get_serialized_string
+ serialized_string = ""
+ @files.each do |name, file|
+ serialized_string += name + ":" + file.serialize.length.to_s + ":" + file.serialize
+ end
+ serialized_string
+ end
+
+ def self.parse(string_data)
+ return RBFS::Directory.new if string_data == nil
+ dir = Serialize.parse_information string_data
+ dir
+ end
+end
+
+class Serialize
+ @dir = RBFS::Directory.new
+
+ def self.parse_information(string_data)
+ split_data = string_data.split(":")
+ temp_count, data_size = Serialize.parse_file_info split_data
+ Serialize.parse_dir_info split_data, temp_count, data_size
+ @dir
+ end
+
+
+ def self.parse_file_info(split_arr, cur_file = 0, counter = 1, file_size = 0)
+ return if cur_file == split_arr[0].to_i # number of files
+ file = Serialize.split_file_info split_arr, counter, file_size
+ @dir.add_file file["name"], RBFS::File.parse(file["data"])
+
+ counter += 3
+ cur_file += 1
+ r2, r3 = Serialize.parse_file_info split_arr, cur_file, counter, file["size"]
+
+ counter, file_size = counter + r2, file_size + r3 unless r2 == nil and r3 == nil
+ return counter, file_size
+ end
+
+ def self.split_file_info(split_arr, counter, size)
+ data = split_arr[counter - 1] + ":" + split_arr[counter]
+ name = data.slice(size..data.length)
+ name = split_arr[counter] if counter == 1
+ size = split_arr[counter + 1].to_i
+ res_data = (split_arr[counter + 2] + ":" + split_arr[counter + 3]).slice(0...size)
+
+ return { "name" => name, "data" => res_data, "size" => size }
+ end
+
+ def self.parse_dir_info(split_arr, counter, file_size, dir_counter = 0)
+ dir_info = Serialize.split_directory_info split_arr, counter, file_size
+ dir_name = split_arr[counter - 3].to_s
+ @dir.add_directory dir_name, RBFS::Directory.new if dir_info["count"] == 0
+ return if dir_counter == dir_info["count"]
+
+ @dir.add_directory dir_info["name"], RBFS::Directory.parse(temp_dir_data)
+ counter += 3
+ dir_counter += 1
+
+ Serialize.parse_dir_info(dir, split_arr, counter, file_size, dir_counter)
+ end
+
+ def self.split_directory_info(split_array, counter, file_size)
+ name = split_array[counter + 1].to_s
+ data = split_array[counter - 1].to_s + ":" + split_array[counter].to_s
+ count = data.slice(file_size..data.length).to_i
+ data_size = split_array[counter + 1].to_s.to_i
+ dir_data = split_array[counter + 2].to_s.slice(0, data_size)
+ dir_data = nil if data_size == 0
+
+ return { "name" => name, "data" => data, "count" => count,
+ "data_size" => data_size, "dir_data" => dir_data }
+ end
+end

Константин обнови решението на 10.11.2014 16:55 (преди над 9 години)

module RBFS
end
class RBFS::File
attr_accessor :data
def initialize(object = nil, file_type = nil)
@data = object
@type = file_type.to_sym if file_type != nil
set_type
end
def data_type
@type
end
def set_type
@type = :nil if @data == nil
@type = :string if @data.is_a? String
@type = :symbol if @data.is_a? Symbol
@type = :number if @data.is_a? Integer or @data.is_a? Float
@type = :boolean if !!@data == @data
end
def serialize
@type.to_s + ":" + @data.to_s
end
def self.parse(string_data)
- RBFS::File.new string_data.split(":")[1], string_data.split(":")[0]
+ split_data = string_data.split(":")
+ content = split_data[1]
+ if split_data.size > 2
+ content += ":" + split_data[2...split_data.size].join(":")
+ end
+ RBFS::File.new content, split_data[0]
end
end
class RBFS::Directory
attr_reader :files
attr_reader :directories
def initialize
@files = {}
@directories = {}
end
def add_file(name, file)
@files[name] = file
end
def add_directory(name, directory = RBFS::Directory.new)
@directories[name] = directory
end
def [](name)
return @directories[name] if @directories.include? name
return @files[name] if @files.include? name
nil
end
def serialize
serialized_string = @files.size.to_s + ":" + get_serialized_string
serialized_string += @directories.size.to_s + ":"
@directories.each do |name, directory|
serialized_string << name + ":" + directory.serialize.size.to_s
serialized_string << ":" + directory.serialize
end
serialized_string
end
def get_serialized_string
serialized_string = ""
@files.each do |name, file|
serialized_string += name + ":" + file.serialize.length.to_s + ":" + file.serialize
end
serialized_string
end
def self.parse(string_data)
return RBFS::Directory.new if string_data == nil
- dir = Serialize.parse_information string_data
+ dir = RBFS::Serialize.parse_information string_data
dir
end
end
-class Serialize
+class RBFS::Serialize
@dir = RBFS::Directory.new
def self.parse_information(string_data)
split_data = string_data.split(":")
- temp_count, data_size = Serialize.parse_file_info split_data
- Serialize.parse_dir_info split_data, temp_count, data_size
+ temp_count, data_size = RBFS::Serialize.parse_file_info split_data
+ RBFS::Serialize.parse_dir_info split_data, temp_count, data_size
@dir
end
def self.parse_file_info(split_arr, cur_file = 0, counter = 1, file_size = 0)
return if cur_file == split_arr[0].to_i # number of files
- file = Serialize.split_file_info split_arr, counter, file_size
+ file = RBFS::Serialize.split_file_info split_arr, counter, file_size
@dir.add_file file["name"], RBFS::File.parse(file["data"])
counter += 3
cur_file += 1
- r2, r3 = Serialize.parse_file_info split_arr, cur_file, counter, file["size"]
+ r2, r3 = RBFS::Serialize.parse_file_info split_arr, cur_file, counter, file["size"]
counter, file_size = counter + r2, file_size + r3 unless r2 == nil and r3 == nil
return counter, file_size
end
def self.split_file_info(split_arr, counter, size)
data = split_arr[counter - 1] + ":" + split_arr[counter]
name = data.slice(size..data.length)
name = split_arr[counter] if counter == 1
size = split_arr[counter + 1].to_i
res_data = (split_arr[counter + 2] + ":" + split_arr[counter + 3]).slice(0...size)
return { "name" => name, "data" => res_data, "size" => size }
end
def self.parse_dir_info(split_arr, counter, file_size, dir_counter = 0)
- dir_info = Serialize.split_directory_info split_arr, counter, file_size
+ dir_info = RBFS::Serialize.split_directory_info split_arr, counter, file_size
dir_name = split_arr[counter - 3].to_s
@dir.add_directory dir_name, RBFS::Directory.new if dir_info["count"] == 0
return if dir_counter == dir_info["count"]
@dir.add_directory dir_info["name"], RBFS::Directory.parse(temp_dir_data)
counter += 3
dir_counter += 1
- Serialize.parse_dir_info(dir, split_arr, counter, file_size, dir_counter)
+ RBFS::Serialize.parse_dir_info(dir, split_arr, counter, file_size, dir_counter)
end
def self.split_directory_info(split_array, counter, file_size)
name = split_array[counter + 1].to_s
data = split_array[counter - 1].to_s + ":" + split_array[counter].to_s
count = data.slice(file_size..data.length).to_i
data_size = split_array[counter + 1].to_s.to_i
dir_data = split_array[counter + 2].to_s.slice(0, data_size)
dir_data = nil if data_size == 0
return { "name" => name, "data" => data, "count" => count,
"data_size" => data_size, "dir_data" => dir_data }
end
end