diff --git a/lib/sof/array.rb b/lib/sof/array.rb index 02b2177e..ff7f73d2 100644 --- a/lib/sof/array.rb +++ b/lib/sof/array.rb @@ -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 diff --git a/lib/sof/members.rb b/lib/sof/members.rb index 732ce07e..f086bda8 100644 --- a/lib/sof/members.rb +++ b/lib/sof/members.rb @@ -7,7 +7,7 @@ module Sof @root = root @counter = 1 @objects = {} - add(root ,0 ) + add(root , 0) end attr_reader :objects , :root diff --git a/lib/sof/occurence.rb b/lib/sof/occurence.rb index 52322762..2493ce94 100644 --- a/lib/sof/occurence.rb +++ b/lib/sof/occurence.rb @@ -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 diff --git a/lib/sof/writer.rb b/lib/sof/writer.rb index f3e5115a..5481f451 100644 --- a/lib/sof/writer.rb +++ b/lib/sof/writer.rb @@ -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 diff --git a/test/sof.rb b/test/sof.rb index 061edd1a..b5f184ee 100644 --- a/test/sof.rb +++ b/test/sof.rb @@ -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 \ No newline at end of file