diff --git a/lib/sof/members.rb b/lib/sof/members.rb index 5ef8098d..732ce07e 100644 --- a/lib/sof/members.rb +++ b/lib/sof/members.rb @@ -1,6 +1,8 @@ module Sof class Members + include Util + def initialize root @root = root @counter = 1 @@ -10,7 +12,7 @@ module Sof attr_reader :objects , :root def add object , level - return if Members.is_value?(object) + return if is_value?(object) if( @objects.has_key?(object) ) occurence = @objects[object] occurence.level = level if occurence.level > level @@ -21,7 +23,7 @@ module Sof @counter = @counter + 1 attributes = attributes_for(object) attributes.each do |a| - val = object.instance_variable_get "@#{a}".to_sym + val = get_value( object , a) add(val , level + 1) end if( object.is_a? Array ) @@ -30,23 +32,5 @@ module Sof end end end - - def self.is_value? o - return true if o == true - return true if o == false - return true if o == nil - return true if o.class == Fixnum - return true if o.class == Symbol - return true if o.class == String - return false - end - - def attributes_for object - if( Known.is( object.class )) - Known.attributes(object.class) - else - object.instance_variables.collect{|i| i.to_s[1..-1].to_sym } # chop of @ - end - end end end diff --git a/lib/sof/util.rb b/lib/sof/util.rb new file mode 100644 index 00000000..4e1eb6be --- /dev/null +++ b/lib/sof/util.rb @@ -0,0 +1,26 @@ +module Sof + module Util + def is_value? o + return true if o == true + return true if o == false + return true if o == nil + return true if o.class == Fixnum + return true if o.class == Symbol + return true if o.class == String + return false + end + + def get_value(object,name) + object.instance_variable_get "@#{name}".to_sym + end + + def attributes_for object + if( Known.is( object.class )) + Known.attributes(object.class) + else + object.instance_variables.collect{|i| i.to_s[1..-1].to_sym } # chop of @ + end + end + + end +end