fixing arrays/hashs and starting complex objects

This commit is contained in:
Torsten Ruger
2014-08-17 21:44:34 +03:00
parent 9669831f78
commit b0472753f4
5 changed files with 22 additions and 9 deletions

View File

@ -1,8 +1,8 @@
Array.class_eval do
def to_sof_node(members , level)
def to_sof_node(writer , level)
node = Sof::NodeList.new()
each do |object|
node.add members.to_sof_node( object )
node.add writer.to_sof_node( object )
end
node
end

View File

@ -1,9 +1,9 @@
Hash.class_eval do
def to_sof_node(members , level)
def to_sof_node(writer , level)
node = Sof::NodeList.new()
each do |key , object|
k = key.to_sof() + ": "
v = members.to_sof_node( object )
v = writer.to_sof_node( object )
v.data = "#{k}#{v.data}"
node.add v
end

View File

@ -20,8 +20,8 @@ module Sof
end
class NodeList < SimpleNode
def initialize
super(nil)
def initialize data = nil
super(data)
@children = []
end
attr_accessor :children

View File

@ -30,12 +30,13 @@ module Sof
attributes = attributes_for(object)
immediate , extended = attributes.partition {|a| is_value?(get_value(object , a) ) }
head += immediate.collect {|a| "#{a}: #{get_value(object , a).to_sof()}"}.join(", ") + ")"
node = SimpleNode.new(head)
ex = {}
extended.each do |a|
val = get_value(object , a)
node.add to_sof_node(val)
ex[a] = val
end
node = ex.to_sof_node(self,level+1)
node.data = head
node
end