Решение на Трета задача от Людмила Савова

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

Към профила на Людмила Савова

Резултати

  • 2 точки от тестове
  • 0 бонус точки
  • 2 точки общо
  • 18 успешни тест(а)
  • 26 неуспешни тест(а)

Код

module RBFS
DATA_TYPE = { "String" => :string,
"Numeric" => :number,
"NilClass" => :nil,
"Symbol" => :symbol,
"TrueClass" => :boolean,
"FalseClass" => :boolean }
class File
attr_accessor :data_type
attr_accessor :data
def initialize(object = nil)
@object = object
@data_type = data_type?(@object)
@data = @object.to_s
end
def parse(string_data)
data = string_data.split(":", 2).last
case string_data.split(":", 2).first
when "string" then return File.new(data)
when "number" then return File.new(eval(data))
when "nil" then return File.new()
when "symbol" then return File.new(data.to_sym)
when "boolean" then return File.new(eval(data))
end
end
def data_type?(object)
DATA_TYPE.select{ |key, value| object.is_a? eval(key) }.values[0]
end
def serialize
@data_type.to_s + ':' + @data
end
end
class Directory
attr_accessor :files
attr_accessor :directories
def initialize()
@files = {}
@directories = {}
end
def add_file(name, file)
@files[name] = file
end
def add_directory(name = '', directory = Directory.new)
@directories[name] = directory
end
def [](name)
if @directories[name] != nil then return @directories[name] end
if @files[name] != nil then return @files[name] end
end
def serialize()
serialized_files = @files.size.to_s + ':'
serialized_directories = @directories.size.to_s + ':'
@files.each do |name, file|
serialized_files +=name + ':' + file.serialize.length.to_s + ':' + file.serialize
end
@directories.each do |name, directory|
serialized_directories += name + ':' + directory.serialize.length.to_s \
+ ':' + directory.serialize
end
serialized_files + serialized_directories
end
def parse(string_data)
end
end
end

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

..........FFFF.....F...FFFFFFFFFFFFFFFFFFFFF

Failures:

  1) RBFS Directory serialization ::parse can parse empty directories
     Failure/Error: parsed_directory = RBFS::Directory.parse('0:0:')
     NoMethodError:
       undefined method `parse' for RBFS::Directory:Class
     # /tmp/d20141111-26053-1fnpnn7/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 directories with files
     Failure/Error: parsed_directory = RBFS::Directory.parse(simple_serialized_string)
     NoMethodError:
       undefined method `parse' for RBFS::Directory:Class
     # /tmp/d20141111-26053-1fnpnn7/spec.rb:108: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 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 `parse' for RBFS::Directory:Class
     # /tmp/d20141111-26053-1fnpnn7/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)>'

  4) RBFS Directory serialization ::parse can parse directories recursively
     Failure/Error: parsed_directory = RBFS::Directory.parse(recursive_serialized_string)
     NoMethodError:
       undefined method `parse' for RBFS::Directory:Class
     # /tmp/d20141111-26053-1fnpnn7/spec.rb:125: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 has nil as initial data
     Failure/Error: expect(file.data).to eq nil
       
       expected: nil
            got: ""
       
       (compared using ==)
     # /tmp/d20141111-26053-1fnpnn7/spec.rb:203:in `block (3 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 nil can be serialized
     Failure/Error: expect(file.serialize).to eq 'nil:'
     TypeError:
       no implicit conversion of nil into String
     # /tmp/d20141111-26053-1fnpnn7/solution.rb:34:in `+'
     # /tmp/d20141111-26053-1fnpnn7/solution.rb:34:in `serialize'
     # /tmp/d20141111-26053-1fnpnn7/spec.rb:226: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 nil can be parsed
     Failure/Error: file = RBFS::File.parse('nil:')
     NoMethodError:
       undefined method `parse' for RBFS::File:Class
     # /tmp/d20141111-26053-1fnpnn7/spec.rb:230: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 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-1fnpnn7/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)>'

  9) 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-1fnpnn7/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)>'

  10) RBFS File data type string can be parsed
     Failure/Error: file = RBFS::File.parse('string:Hey there')
     NoMethodError:
       undefined method `parse' for RBFS::File:Class
     # /tmp/d20141111-26053-1fnpnn7/spec.rb:248: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 string can parse a string with colons
     Failure/Error: file = RBFS::File.parse('string:Hay :)')
     NoMethodError:
       undefined method `parse' for RBFS::File:Class
     # /tmp/d20141111-26053-1fnpnn7/spec.rb:255: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 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-1fnpnn7/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)>'

  13) RBFS File data type symbol can be serialized
     Failure/Error: expect(file.serialize).to eq 'symbol:yo'
     TypeError:
       no implicit conversion of Symbol into String
     # /tmp/d20141111-26053-1fnpnn7/solution.rb:34:in `+'
     # /tmp/d20141111-26053-1fnpnn7/solution.rb:34:in `serialize'
     # /tmp/d20141111-26053-1fnpnn7/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)>'

  14) RBFS File data type symbol can be parsed
     Failure/Error: file = RBFS::File.parse('symbol:hello')
     NoMethodError:
       undefined method `parse' for RBFS::File:Class
     # /tmp/d20141111-26053-1fnpnn7/spec.rb:274: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 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-1fnpnn7/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)>'

  16) RBFS File data type number can be serialized
     Failure/Error: expect(file.serialize).to eq 'number:666'
     TypeError:
       no implicit conversion of Fixnum into String
     # /tmp/d20141111-26053-1fnpnn7/solution.rb:34:in `+'
     # /tmp/d20141111-26053-1fnpnn7/solution.rb:34:in `serialize'
     # /tmp/d20141111-26053-1fnpnn7/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)>'

  17) RBFS File data type number can be parsed
     Failure/Error: file = RBFS::File.parse('number:1234')
     NoMethodError:
       undefined method `parse' for RBFS::File:Class
     # /tmp/d20141111-26053-1fnpnn7/spec.rb:293: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)>'

  18) 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-1fnpnn7/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)>'

  19) RBFS File data type float number can be serialized
     Failure/Error: expect(file.serialize).to eq 'number:666.6'
     TypeError:
       no implicit conversion of Float into String
     # /tmp/d20141111-26053-1fnpnn7/solution.rb:34:in `+'
     # /tmp/d20141111-26053-1fnpnn7/solution.rb:34:in `serialize'
     # /tmp/d20141111-26053-1fnpnn7/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)>'

  20) RBFS File data type float number can be parsed
     Failure/Error: file = RBFS::File.parse('number:3.14')
     NoMethodError:
       undefined method `parse' for RBFS::File:Class
     # /tmp/d20141111-26053-1fnpnn7/spec.rb:312: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)>'

  21) 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-1fnpnn7/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)>'

  22) RBFS File data type boolean true can be serialized
     Failure/Error: expect(file.serialize).to eq 'boolean:true'
     TypeError:
       no implicit conversion of true into String
     # /tmp/d20141111-26053-1fnpnn7/solution.rb:34:in `+'
     # /tmp/d20141111-26053-1fnpnn7/solution.rb:34:in `serialize'
     # /tmp/d20141111-26053-1fnpnn7/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)>'

  23) RBFS File data type boolean true can be parsed
     Failure/Error: file = RBFS::File.parse('boolean:true')
     NoMethodError:
       undefined method `parse' for RBFS::File:Class
     # /tmp/d20141111-26053-1fnpnn7/spec.rb:332: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)>'

  24) 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-1fnpnn7/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)>'

  25) RBFS File data type boolean false can be serialized
     Failure/Error: expect(file.serialize).to eq 'boolean:false'
     TypeError:
       no implicit conversion of false into String
     # /tmp/d20141111-26053-1fnpnn7/solution.rb:34:in `+'
     # /tmp/d20141111-26053-1fnpnn7/solution.rb:34:in `serialize'
     # /tmp/d20141111-26053-1fnpnn7/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)>'

  26) RBFS File data type boolean false can be parsed
     Failure/Error: file = RBFS::File.parse('boolean:false')
     NoMethodError:
       undefined method `parse' for RBFS::File:Class
     # /tmp/d20141111-26053-1fnpnn7/spec.rb:351: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.05317 seconds
44 examples, 26 failures

Failed examples:

rspec /tmp/d20141111-26053-1fnpnn7/spec.rb:100 # RBFS Directory serialization ::parse can parse empty directories
rspec /tmp/d20141111-26053-1fnpnn7/spec.rb:107 # RBFS Directory serialization ::parse can parse directories with files
rspec /tmp/d20141111-26053-1fnpnn7/spec.rb:116 # RBFS Directory serialization ::parse can parse directory trees without files
rspec /tmp/d20141111-26053-1fnpnn7/spec.rb:124 # RBFS Directory serialization ::parse can parse directories recursively
rspec /tmp/d20141111-26053-1fnpnn7/spec.rb:202 # RBFS File has nil as initial data
rspec /tmp/d20141111-26053-1fnpnn7/spec.rb:225 # RBFS File data type nil can be serialized
rspec /tmp/d20141111-26053-1fnpnn7/spec.rb:229 # RBFS File data type nil can be parsed
rspec /tmp/d20141111-26053-1fnpnn7/spec.rb:239 # RBFS File data type string can be detected
rspec /tmp/d20141111-26053-1fnpnn7/spec.rb:243 # RBFS File data type string can be serialized
rspec /tmp/d20141111-26053-1fnpnn7/spec.rb:247 # RBFS File data type string can be parsed
rspec /tmp/d20141111-26053-1fnpnn7/spec.rb:254 # RBFS File data type string can parse a string with colons
rspec /tmp/d20141111-26053-1fnpnn7/spec.rb:265 # RBFS File data type symbol can be detected
rspec /tmp/d20141111-26053-1fnpnn7/spec.rb:269 # RBFS File data type symbol can be serialized
rspec /tmp/d20141111-26053-1fnpnn7/spec.rb:273 # RBFS File data type symbol can be parsed
rspec /tmp/d20141111-26053-1fnpnn7/spec.rb:284 # RBFS File data type number can be detected
rspec /tmp/d20141111-26053-1fnpnn7/spec.rb:288 # RBFS File data type number can be serialized
rspec /tmp/d20141111-26053-1fnpnn7/spec.rb:292 # RBFS File data type number can be parsed
rspec /tmp/d20141111-26053-1fnpnn7/spec.rb:303 # RBFS File data type float number can be detected
rspec /tmp/d20141111-26053-1fnpnn7/spec.rb:307 # RBFS File data type float number can be serialized
rspec /tmp/d20141111-26053-1fnpnn7/spec.rb:311 # RBFS File data type float number can be parsed
rspec /tmp/d20141111-26053-1fnpnn7/spec.rb:321 # RBFS File data type boolean true can be detected
rspec /tmp/d20141111-26053-1fnpnn7/spec.rb:326 # RBFS File data type boolean true can be serialized
rspec /tmp/d20141111-26053-1fnpnn7/spec.rb:331 # RBFS File data type boolean true can be parsed
rspec /tmp/d20141111-26053-1fnpnn7/spec.rb:340 # RBFS File data type boolean false can be detected
rspec /tmp/d20141111-26053-1fnpnn7/spec.rb:345 # RBFS File data type boolean false can be serialized
rspec /tmp/d20141111-26053-1fnpnn7/spec.rb:350 # RBFS File data type boolean false can be parsed

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

Людмила обнови решението на 08.11.2014 17:08 (преди над 9 години)

+module RBFS
+ DATA_TYPE = { "String" => :string,
+ "Numeric" => :number,
+ "NilClass" => :nil,
+ "Symbol" => :symbol,
+ "TrueClass" => :boolean,
+ "FalseClass" => :boolean }
+ class File
+ attr_accessor :data_type
+ attr_accessor :data
+ attr_accessor :serialize
+ attr_accessor :parse
+ def initialize(object = nil)
+ @object = object
+ @data_type = data_type?(@object)
+ @data = @object.to_s
+ end
+
+ def parse(string_data)
+ data = string_data.split(":", 2).last
+ case string_data.split(":", 2).first
+ when "string" then return File.new(data)
+ when "number" then return File.new(eval(data))
+ when "nil" then return File.new()
+ when "symbol" then return File.new(data.to_sym)
+ when "boolean" then return File.new(eval(data))
+ end
+ end
+
+ def data_type?(object)
+ DATA_TYPE.select{ |key, value| object.is_a? eval(key) }.values[0]
+ end
+
+ def serialize
+ @data_type.to_s + ':' + @data
+ end
+ end
+
+ class Directory
+ attr_accessor :files
+ attr_accessor :directories
+ def initialize()
+ @files = {}
+ @directories = {}
+ end
+
+ def add_file(name, file)
+ @files[name] = file
+ end
+
+ def add_directory(name = '', directory = Directory.new)
+ @directories[name] = directory
+ end
+
+ def [](name)
+ if @directories[name] != nil then return @directories[name] end
+ if @files[name] != nil then return @files[name] end
+ end
+
+ def serialize()
+ serialized_files = @files.size.to_s + ':'
+ serialized_directories = @directories.size.to_s + ':'
+ @files.each do |name, file|
+ serialized_files +=name + ':' + file.serialize.length.to_s + ':' + file.serialize
+ end
+ @directories.each do |name, directory|
+ serialized_directories += name + ':' + directory.serialize.length.to_s \
+ + ':' + directory.serialize
+ end
+ serialized_files.chomp + serialized_directories
+ end
+
+ def parse(string_data)
+ end
+
+ end
+end

Людмила обнови решението на 08.11.2014 18:06 (преди над 9 години)

module RBFS
DATA_TYPE = { "String" => :string,
"Numeric" => :number,
"NilClass" => :nil,
"Symbol" => :symbol,
"TrueClass" => :boolean,
"FalseClass" => :boolean }
class File
attr_accessor :data_type
attr_accessor :data
- attr_accessor :serialize
- attr_accessor :parse
+
def initialize(object = nil)
@object = object
@data_type = data_type?(@object)
@data = @object.to_s
end
def parse(string_data)
data = string_data.split(":", 2).last
case string_data.split(":", 2).first
when "string" then return File.new(data)
when "number" then return File.new(eval(data))
when "nil" then return File.new()
when "symbol" then return File.new(data.to_sym)
when "boolean" then return File.new(eval(data))
end
end
def data_type?(object)
DATA_TYPE.select{ |key, value| object.is_a? eval(key) }.values[0]
end
def serialize
@data_type.to_s + ':' + @data
end
end
class Directory
attr_accessor :files
attr_accessor :directories
+
def initialize()
@files = {}
@directories = {}
end
def add_file(name, file)
@files[name] = file
end
def add_directory(name = '', directory = Directory.new)
@directories[name] = directory
end
def [](name)
if @directories[name] != nil then return @directories[name] end
if @files[name] != nil then return @files[name] end
end
def serialize()
serialized_files = @files.size.to_s + ':'
serialized_directories = @directories.size.to_s + ':'
@files.each do |name, file|
serialized_files +=name + ':' + file.serialize.length.to_s + ':' + file.serialize
end
@directories.each do |name, directory|
serialized_directories += name + ':' + directory.serialize.length.to_s \
+ ':' + directory.serialize
end
serialized_files.chomp + serialized_directories
end
def parse(string_data)
end
end
end

Людмила обнови решението на 10.11.2014 00:21 (преди над 9 години)

module RBFS
DATA_TYPE = { "String" => :string,
"Numeric" => :number,
"NilClass" => :nil,
"Symbol" => :symbol,
"TrueClass" => :boolean,
"FalseClass" => :boolean }
class File
attr_accessor :data_type
attr_accessor :data
def initialize(object = nil)
@object = object
@data_type = data_type?(@object)
@data = @object.to_s
end
def parse(string_data)
data = string_data.split(":", 2).last
case string_data.split(":", 2).first
when "string" then return File.new(data)
when "number" then return File.new(eval(data))
when "nil" then return File.new()
when "symbol" then return File.new(data.to_sym)
when "boolean" then return File.new(eval(data))
end
end
def data_type?(object)
DATA_TYPE.select{ |key, value| object.is_a? eval(key) }.values[0]
end
def serialize
@data_type.to_s + ':' + @data
end
end
class Directory
attr_accessor :files
attr_accessor :directories
def initialize()
@files = {}
@directories = {}
end
def add_file(name, file)
@files[name] = file
end
def add_directory(name = '', directory = Directory.new)
@directories[name] = directory
end
def [](name)
if @directories[name] != nil then return @directories[name] end
if @files[name] != nil then return @files[name] end
end
def serialize()
serialized_files = @files.size.to_s + ':'
serialized_directories = @directories.size.to_s + ':'
@files.each do |name, file|
serialized_files +=name + ':' + file.serialize.length.to_s + ':' + file.serialize
end
@directories.each do |name, directory|
serialized_directories += name + ':' + directory.serialize.length.to_s \
+ ':' + directory.serialize
end
- serialized_files.chomp + serialized_directories
+ serialized_files + serialized_directories
end
def parse(string_data)
end
-
end
end