2014-08-13 19:05:00 +02:00
|
|
|
module Sof
|
|
|
|
|
|
|
|
class Members
|
2014-08-14 18:48:06 +02:00
|
|
|
include Util
|
|
|
|
|
2014-08-13 19:05:00 +02:00
|
|
|
def initialize root
|
|
|
|
@root = root
|
|
|
|
@counter = 1
|
|
|
|
@objects = {}
|
2014-08-14 19:24:26 +02:00
|
|
|
add(root , 0)
|
2014-08-13 19:05:00 +02:00
|
|
|
end
|
2014-08-14 18:24:18 +02:00
|
|
|
attr_reader :objects , :root
|
2014-08-14 16:40:56 +02:00
|
|
|
|
2014-08-13 19:05:00 +02:00
|
|
|
def add object , level
|
2014-08-14 18:48:06 +02:00
|
|
|
return if is_value?(object)
|
2014-08-13 19:05:00 +02:00
|
|
|
if( @objects.has_key?(object) )
|
2014-08-14 16:40:56 +02:00
|
|
|
occurence = @objects[object]
|
2014-08-13 19:05:00 +02:00
|
|
|
occurence.level = level if occurence.level > level
|
2014-08-14 18:24:18 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
o = Occurence.new( object , @counter , level )
|
|
|
|
@objects[object] = o
|
|
|
|
@counter = @counter + 1
|
|
|
|
attributes = attributes_for(object)
|
|
|
|
attributes.each do |a|
|
2014-08-14 18:48:06 +02:00
|
|
|
val = get_value( object , a)
|
2014-08-14 18:24:18 +02:00
|
|
|
add(val , level + 1)
|
|
|
|
end
|
|
|
|
if( object.is_a? Array )
|
|
|
|
object.each do |a|
|
|
|
|
add(a , level + 1)
|
2014-08-13 19:05:00 +02:00
|
|
|
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
|
2014-08-13 19:05:00 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|