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

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

Към профила на Светлозар Стефанов

Резултати

  • 1 точка от тестове
  • 0 бонус точки
  • 1 точка общо
  • 8 успешни тест(а)
  • 36 неуспешни тест(а)

Код

module RBFS
class File
def initialize(data = nil)
@data = data
case data
when Fixnum then @data_type = :number
when Symbol then @data_type = :symbol
when NilClass then @data_type = :nil
when String then @data_type = :string
else @data_type = :boolean
end
end
attr_reader :data_type
attr_accessor :data
def serialize()
@data_type.to_s + ':' + @data.to_s
end
def self.parse(string_data)
temp = string_data.split(':')
file = File.new
file.data_type = temp[0].to_sym
file.data = temp[1]
file
end
end
class Directory
attr_reader :files
attr_reader :directories
def initialize()
@files = {}
@directories = {}
end
def add_file(name, file)
if @files.has_key? name then
nil
else
@files[name] = directory
end
end
def add_directory(name, directory)
if @directories.has_key? name then
nil
else
@directories[name] = directory
end
end
def [](name)
if @directories.has_key? name then
@directories[name]
else
@files[name]
end
end
def serialize()
end
def self.parse(string_data)
end
end
end

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

FF..F.FFFFFFFFFFFFF.....FFFFFFFFFFFFFFFFFFFF

Failures:

  1) RBFS Directory can add a file
     Failure/Error: directory.add_file 'README', file
     NameError:
       undefined local variable or method `directory' for #<RBFS::Directory:0xb9de7024 @files={}, @directories={}>
     # /tmp/d20141111-26053-dgmexr/solution.rb:43:in `add_file'
     # /tmp/d20141111-26053-dgmexr/spec.rb:144: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)>'

  2) RBFS Directory can create empty directory
     Failure/Error: directory.add_directory 'home'
     ArgumentError:
       wrong number of arguments (1 for 2)
     # /tmp/d20141111-26053-dgmexr/solution.rb:47:in `add_directory'
     # /tmp/d20141111-26053-dgmexr/spec.rb:150: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)>'

  3) RBFS Directory without files can be serialized
     Failure/Error: expect(directory.serialize).to eq '0:0:'
       
       expected: "0:0:"
            got: nil
       
       (compared using ==)
     # /tmp/d20141111-26053-dgmexr/spec.rb:11:in `block (4 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 with files and directories returns correct file hash
     Failure/Error: directory.add_file('README',  readme)
     NameError:
       undefined local variable or method `directory' for #<RBFS::Directory:0xb9de0030 @files={}, @directories={}>
     # /tmp/d20141111-26053-dgmexr/solution.rb:43:in `add_file'
     # /tmp/d20141111-26053-dgmexr/spec.rb:27:in `block (4 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 Directory with files and directories returns correct directory hash
     Failure/Error: directory.add_file('README',  readme)
     NameError:
       undefined local variable or method `directory' for #<RBFS::Directory:0xb9ddf310 @files={}, @directories={}>
     # /tmp/d20141111-26053-dgmexr/solution.rb:43:in `add_file'
     # /tmp/d20141111-26053-dgmexr/spec.rb:27:in `block (4 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 Directory serialization #serialize can serialize
     Failure/Error: directory.add_file 'README',  RBFS::File.new('Hello world!')
     NameError:
       undefined local variable or method `directory' for #<RBFS::Directory:0xb9dde3ac @files={}, @directories={}>
     # /tmp/d20141111-26053-dgmexr/solution.rb:43:in `add_file'
     # /tmp/d20141111-26053-dgmexr/spec.rb:77: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 Directory serialization #serialize can serialize multiple directories recursively
     Failure/Error: directory.add_file 'README',  RBFS::File.new('Hello world!')
     NameError:
       undefined local variable or method `directory' for #<RBFS::Directory:0xb9ddd54c @files={}, @directories={}>
     # /tmp/d20141111-26053-dgmexr/solution.rb:43:in `add_file'
     # /tmp/d20141111-26053-dgmexr/spec.rb:85: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 Directory serialization ::parse can parse empty directories
     Failure/Error: expect(parsed_directory.files      ).to eq({})
     NoMethodError:
       undefined method `files' for nil:NilClass
     # /tmp/d20141111-26053-dgmexr/spec.rb:103: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 Directory serialization ::parse can parse directories with files
     Failure/Error: expect(parsed_directory.files.size     ).to eq    2
     NoMethodError:
       undefined method `files' for nil:NilClass
     # /tmp/d20141111-26053-dgmexr/spec.rb:110: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 Directory serialization ::parse can parse directory trees without files
     Failure/Error: expect(parsed_directory['dir1']        ).to be_an RBFS::Directory
     NoMethodError:
       undefined method `[]' for nil:NilClass
     # /tmp/d20141111-26053-dgmexr/spec.rb:119: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 Directory serialization ::parse can parse directories recursively
     Failure/Error: expect(parsed_directory.files.size     ).to eq 2
     NoMethodError:
       undefined method `files' for nil:NilClass
     # /tmp/d20141111-26053-dgmexr/spec.rb:127: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 Directory #[] can walk a single directory
     Failure/Error: ruby.add_file           'file', file
     NameError:
       undefined local variable or method `directory' for #<RBFS::Directory:0xb9dd86f0 @files={}, @directories={}>
     # /tmp/d20141111-26053-dgmexr/solution.rb:43:in `add_file'
     # /tmp/d20141111-26053-dgmexr/spec.rb:174:in `block (4 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 Directory #[] can walk multiple directories
     Failure/Error: ruby.add_file           'file', file
     NameError:
       undefined local variable or method `directory' for #<RBFS::Directory:0xb9dd7494 @files={}, @directories={}>
     # /tmp/d20141111-26053-dgmexr/solution.rb:43:in `add_file'
     # /tmp/d20141111-26053-dgmexr/spec.rb:174:in `block (4 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 Directory #[] can get files
     Failure/Error: ruby.add_file           'file', file
     NameError:
       undefined local variable or method `directory' for #<RBFS::Directory:0xb9dd6468 @files={}, @directories={}>
     # /tmp/d20141111-26053-dgmexr/solution.rb:43:in `add_file'
     # /tmp/d20141111-26053-dgmexr/spec.rb:174:in `block (4 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 Directory #[] returns nil if directory or file doesnt exist
     Failure/Error: ruby.add_file           'file', file
     NameError:
       undefined local variable or method `directory' for #<RBFS::Directory:0xb9dd5734 @files={}, @directories={}>
     # /tmp/d20141111-26053-dgmexr/solution.rb:43:in `add_file'
     # /tmp/d20141111-26053-dgmexr/spec.rb:174:in `block (4 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 Directory #[] is case-sensitive
     Failure/Error: ruby.add_file           'file', file
     NameError:
       undefined local variable or method `directory' for #<RBFS::Directory:0xb9dd4938 @files={}, @directories={}>
     # /tmp/d20141111-26053-dgmexr/solution.rb:43:in `add_file'
     # /tmp/d20141111-26053-dgmexr/spec.rb:174:in `block (4 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 nil can be parsed
     Failure/Error: file = RBFS::File.parse('nil:')
     NoMethodError:
       undefined method `data_type=' for #<RBFS::File:0xb9e2ac70 @data=nil, @data_type=:nil>
     # /tmp/d20141111-26053-dgmexr/solution.rb:24:in `parse'
     # /tmp/d20141111-26053-dgmexr/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)>'

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

  19) 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-dgmexr/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)>'

  20) RBFS File data type string can be parsed
     Failure/Error: file = RBFS::File.parse('string:Hey there')
     NoMethodError:
       undefined method `data_type=' for #<RBFS::File:0xb9e26f1c @data=nil, @data_type=:nil>
     # /tmp/d20141111-26053-dgmexr/solution.rb:24:in `parse'
     # /tmp/d20141111-26053-dgmexr/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)>'

  21) RBFS File data type string can parse a string with colons
     Failure/Error: file = RBFS::File.parse('string:Hay :)')
     NoMethodError:
       undefined method `data_type=' for #<RBFS::File:0xb9e25f2c @data=nil, @data_type=:nil>
     # /tmp/d20141111-26053-dgmexr/solution.rb:24:in `parse'
     # /tmp/d20141111-26053-dgmexr/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)>'

  22) 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-dgmexr/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)>'

  23) 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-dgmexr/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)>'

  24) RBFS File data type symbol can be parsed
     Failure/Error: file = RBFS::File.parse('symbol:hello')
     NoMethodError:
       undefined method `data_type=' for #<RBFS::File:0xb9e22084 @data=nil, @data_type=:nil>
     # /tmp/d20141111-26053-dgmexr/solution.rb:24:in `parse'
     # /tmp/d20141111-26053-dgmexr/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)>'

  25) 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-dgmexr/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)>'

  26) 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-dgmexr/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)>'

  27) RBFS File data type number can be parsed
     Failure/Error: file = RBFS::File.parse('number:1234')
     NoMethodError:
       undefined method `data_type=' for #<RBFS::File:0xb9e1e948 @data=nil, @data_type=:nil>
     # /tmp/d20141111-26053-dgmexr/solution.rb:24:in `parse'
     # /tmp/d20141111-26053-dgmexr/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)>'

  28) 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-dgmexr/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)>'

  29) 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-dgmexr/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)>'

  30) RBFS File data type float number can be parsed
     Failure/Error: file = RBFS::File.parse('number:3.14')
     NoMethodError:
       undefined method `data_type=' for #<RBFS::File:0xb9d62360 @data=nil, @data_type=:nil>
     # /tmp/d20141111-26053-dgmexr/solution.rb:24:in `parse'
     # /tmp/d20141111-26053-dgmexr/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)>'

  31) 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-dgmexr/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)>'

  32) 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-dgmexr/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)>'

  33) RBFS File data type boolean true can be parsed
     Failure/Error: file = RBFS::File.parse('boolean:true')
     NoMethodError:
       undefined method `data_type=' for #<RBFS::File:0xb9d5dd9c @data=nil, @data_type=:nil>
     # /tmp/d20141111-26053-dgmexr/solution.rb:24:in `parse'
     # /tmp/d20141111-26053-dgmexr/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)>'

  34) 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-dgmexr/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)>'

  35) 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-dgmexr/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)>'

  36) RBFS File data type boolean false can be parsed
     Failure/Error: file = RBFS::File.parse('boolean:false')
     NoMethodError:
       undefined method `data_type=' for #<RBFS::File:0xb9d59d3c @data=nil, @data_type=:nil>
     # /tmp/d20141111-26053-dgmexr/solution.rb:24:in `parse'
     # /tmp/d20141111-26053-dgmexr/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.04192 seconds
44 examples, 36 failures

Failed examples:

rspec /tmp/d20141111-26053-dgmexr/spec.rb:141 # RBFS Directory can add a file
rspec /tmp/d20141111-26053-dgmexr/spec.rb:149 # RBFS Directory can create empty directory
rspec /tmp/d20141111-26053-dgmexr/spec.rb:10 # RBFS Directory without files can be serialized
rspec /tmp/d20141111-26053-dgmexr/spec.rb:33 # RBFS Directory with files and directories returns correct file hash
rspec /tmp/d20141111-26053-dgmexr/spec.rb:37 # RBFS Directory with files and directories returns correct directory hash
rspec /tmp/d20141111-26053-dgmexr/spec.rb:76 # RBFS Directory serialization #serialize can serialize
rspec /tmp/d20141111-26053-dgmexr/spec.rb:84 # RBFS Directory serialization #serialize can serialize multiple directories recursively
rspec /tmp/d20141111-26053-dgmexr/spec.rb:100 # RBFS Directory serialization ::parse can parse empty directories
rspec /tmp/d20141111-26053-dgmexr/spec.rb:107 # RBFS Directory serialization ::parse can parse directories with files
rspec /tmp/d20141111-26053-dgmexr/spec.rb:116 # RBFS Directory serialization ::parse can parse directory trees without files
rspec /tmp/d20141111-26053-dgmexr/spec.rb:124 # RBFS Directory serialization ::parse can parse directories recursively
rspec /tmp/d20141111-26053-dgmexr/spec.rb:177 # RBFS Directory #[] can walk a single directory
rspec /tmp/d20141111-26053-dgmexr/spec.rb:181 # RBFS Directory #[] can walk multiple directories
rspec /tmp/d20141111-26053-dgmexr/spec.rb:185 # RBFS Directory #[] can get files
rspec /tmp/d20141111-26053-dgmexr/spec.rb:189 # RBFS Directory #[] returns nil if directory or file doesnt exist
rspec /tmp/d20141111-26053-dgmexr/spec.rb:193 # RBFS Directory #[] is case-sensitive
rspec /tmp/d20141111-26053-dgmexr/spec.rb:229 # RBFS File data type nil can be parsed
rspec /tmp/d20141111-26053-dgmexr/spec.rb:239 # RBFS File data type string can be detected
rspec /tmp/d20141111-26053-dgmexr/spec.rb:243 # RBFS File data type string can be serialized
rspec /tmp/d20141111-26053-dgmexr/spec.rb:247 # RBFS File data type string can be parsed
rspec /tmp/d20141111-26053-dgmexr/spec.rb:254 # RBFS File data type string can parse a string with colons
rspec /tmp/d20141111-26053-dgmexr/spec.rb:265 # RBFS File data type symbol can be detected
rspec /tmp/d20141111-26053-dgmexr/spec.rb:269 # RBFS File data type symbol can be serialized
rspec /tmp/d20141111-26053-dgmexr/spec.rb:273 # RBFS File data type symbol can be parsed
rspec /tmp/d20141111-26053-dgmexr/spec.rb:284 # RBFS File data type number can be detected
rspec /tmp/d20141111-26053-dgmexr/spec.rb:288 # RBFS File data type number can be serialized
rspec /tmp/d20141111-26053-dgmexr/spec.rb:292 # RBFS File data type number can be parsed
rspec /tmp/d20141111-26053-dgmexr/spec.rb:303 # RBFS File data type float number can be detected
rspec /tmp/d20141111-26053-dgmexr/spec.rb:307 # RBFS File data type float number can be serialized
rspec /tmp/d20141111-26053-dgmexr/spec.rb:311 # RBFS File data type float number can be parsed
rspec /tmp/d20141111-26053-dgmexr/spec.rb:321 # RBFS File data type boolean true can be detected
rspec /tmp/d20141111-26053-dgmexr/spec.rb:326 # RBFS File data type boolean true can be serialized
rspec /tmp/d20141111-26053-dgmexr/spec.rb:331 # RBFS File data type boolean true can be parsed
rspec /tmp/d20141111-26053-dgmexr/spec.rb:340 # RBFS File data type boolean false can be detected
rspec /tmp/d20141111-26053-dgmexr/spec.rb:345 # RBFS File data type boolean false can be serialized
rspec /tmp/d20141111-26053-dgmexr/spec.rb:350 # RBFS File data type boolean false can be parsed

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

Светлозар обнови решението на 10.11.2014 16:53 (преди около 10 години)

+module RBFS
+ class File
+ def initialize(data = nil)
+ @data = data
+ case data
+ when Fixnum then @data_type = :number
+ when Symbol then @data_type = :symbol
+ when NilClass then @data_type = :nil
+ when String then @data_type = :string
+ else @data_type = :boolean
+ end
+ end
+
+ attr_reader :data_type
+ attr_accessor :data
+
+ def serialize()
+ @data_type.to_s + ':' + @data.to_s
+ end
+
+ def self.parse(string_data)
+ temp = string_data.split(':')
+ file = File.new
+ file.data_type = temp[0].to_sym
+ file.data = temp[1]
+ file
+ end
+ end
+
+ class Directory
+ attr_reader :files
+ attr_reader :directories
+
+ def initialize()
+ @files = {}
+ @directories = {}
+ end
+
+ def add_file(name, file)
+ if @files.has_key? name then
+ nil
+ else
+ @files[name] = directory
+ end
+ end
+
+ def add_directory(name, directory)
+ if @directories.has_key? name then
+ nil
+ else
+ @directories[name] = directory
+ end
+ end
+
+ def [](name)
+ if @directories.has_key? name then
+ @directories[name]
+ else
+ @files[name]
+ end
+ end
+
+ def serialize()
+
+ end
+
+ def self.parse(string_data)
+
+ end
+ end
+end