rubyx/lib/sof/members.rb

43 lines
968 B
Ruby
Raw Normal View History

module Sof
class Members
include Util
def initialize root
@root = root
@counter = 1
@objects = {}
2014-08-14 19:24:26 +02:00
add(root , 0)
end
attr_reader :objects , :root
def add object , level
return if is_value?(object)
2014-08-18 11:49:38 +02:00
if( occurence = @objects[object] )
#puts "reset level #{level} at #{occurence.level}"
occurence.level = level if occurence.level > level
return
end
o = Occurence.new( object , @counter , level )
@objects[object] = o
@counter = @counter + 1
attributes = attributes_for(object)
attributes.each do |a|
val = get_value( object , a)
add(val , level + 1)
end
if( object.is_a? Array )
object.each do |a|
add(a , level + 1)
end
end
2014-08-15 16:18:15 +02:00
if( object.is_a? Hash )
object.each do |a,b|
add(a , level + 1)
add(b , level + 1)
end
end
end
end
end