rubyx/lib/sof/members.rb
2014-08-15 17:18:15 +03:00

43 lines
943 B
Ruby

module Sof
class Members
include Util
def initialize root
@root = root
@counter = 1
@objects = {}
add(root , 0)
end
attr_reader :objects , :root
def add object , level
return if is_value?(object)
if( @objects.has_key?(object) )
occurence = @objects[object]
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
if( object.is_a? Hash )
object.each do |a,b|
add(a , level + 1)
add(b , level + 1)
end
end
end
end
end