fix simple array
This commit is contained in:
parent
2f5ed43073
commit
85dad14cc8
@ -1,8 +1,10 @@
|
||||
Array.class_eval do
|
||||
def to_sof(io , members)
|
||||
def to_sof(io , members , level)
|
||||
each do |object|
|
||||
io.write("\n")
|
||||
io.write(" " * level)
|
||||
io.write("-")
|
||||
members.output(io , object)
|
||||
io.write("\n")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -7,7 +7,7 @@ module Sof
|
||||
@root = root
|
||||
@counter = 1
|
||||
@objects = {}
|
||||
add(root ,0 )
|
||||
add(root , 0)
|
||||
end
|
||||
attr_reader :objects , :root
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
module Sof
|
||||
|
||||
class Occurence
|
||||
def initialize object , level , number
|
||||
@number = number
|
||||
def initialize object , number , level
|
||||
@object = object
|
||||
@number = number
|
||||
@level = level
|
||||
end
|
||||
attr_reader :object , :number
|
||||
|
@ -21,7 +21,7 @@ module Sof
|
||||
indent = " " * occurence.level
|
||||
io.write indent
|
||||
if(object.respond_to? :to_sof) #mainly meant for arrays and hashes
|
||||
object.to_sof(io , self)
|
||||
object.to_sof(io , self , occurence.level)
|
||||
else
|
||||
object_write(object , io)
|
||||
end
|
||||
|
@ -8,7 +8,6 @@ class ObjectWithAttributes
|
||||
end
|
||||
|
||||
class BasicSof < MiniTest::Test
|
||||
|
||||
def test_true
|
||||
out = Sof::Writer.write(true)
|
||||
assert_equal "true" , out
|
||||
@ -19,6 +18,10 @@ class BasicSof < MiniTest::Test
|
||||
end
|
||||
def test_object
|
||||
out = Sof::Writer.write(ObjectWithAttributes.new)
|
||||
assert_equal " ObjectWithAttributes(name: 'some object' ,number: 1234)\n" , out
|
||||
assert_equal "ObjectWithAttributes(name: 'some object' ,number: 1234)\n" , out
|
||||
end
|
||||
def test_simple_array
|
||||
out = Sof::Writer.write([true, 1234])
|
||||
assert_equal "-true\n-1234\n" , out
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user