2014-08-13 20:05:00 +03:00
|
|
|
module Sof
|
|
|
|
|
|
|
|
class Members
|
2014-08-14 19:48:06 +03:00
|
|
|
include Util
|
|
|
|
|
2014-08-13 20:05:00 +03:00
|
|
|
def initialize root
|
|
|
|
@root = root
|
|
|
|
@counter = 1
|
|
|
|
@objects = {}
|
2014-08-18 13:53:05 +03:00
|
|
|
@referenced = false
|
2014-08-14 20:24:26 +03:00
|
|
|
add(root , 0)
|
2014-08-13 20:05:00 +03:00
|
|
|
end
|
2014-08-18 13:53:05 +03:00
|
|
|
attr_reader :objects , :root , :referenced
|
2014-08-14 17:40:56 +03:00
|
|
|
|
2014-08-13 20:05:00 +03:00
|
|
|
def add object , level
|
2014-08-14 19:48:06 +03:00
|
|
|
return if is_value?(object)
|
2014-08-18 12:49:38 +03:00
|
|
|
if( occurence = @objects[object] )
|
2014-08-18 13:33:40 +03:00
|
|
|
#puts "reset level #{level} at #{occurence.level}"
|
2014-08-13 20:05:00 +03:00
|
|
|
occurence.level = level if occurence.level > level
|
2014-08-18 13:53:05 +03:00
|
|
|
occurence.referenced = true
|
2014-08-14 19:24:18 +03: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 19:48:06 +03:00
|
|
|
val = get_value( object , a)
|
2014-08-14 19:24:18 +03:00
|
|
|
add(val , level + 1)
|
|
|
|
end
|
|
|
|
if( object.is_a? Array )
|
|
|
|
object.each do |a|
|
|
|
|
add(a , level + 1)
|
2014-08-13 20:05:00 +03:00
|
|
|
end
|
|
|
|
end
|
2014-08-15 17:18:15 +03:00
|
|
|
if( object.is_a? Hash )
|
|
|
|
object.each do |a,b|
|
|
|
|
add(a , level + 1)
|
|
|
|
add(b , level + 1)
|
|
|
|
end
|
|
|
|
end
|
2014-08-13 20:05:00 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|