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