From 9d5f62eded23a4b8825739d2988594360a52f8cb Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Mon, 18 Aug 2014 17:25:49 +0300 Subject: [PATCH] only marking/counting occurences that are actually referenced, so numbers stay smaller --- lib/sof/members.rb | 6 +++--- lib/sof/occurence.rb | 5 ++--- lib/sof/writer.rb | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/sof/members.rb b/lib/sof/members.rb index 188f324d..1b47832a 100644 --- a/lib/sof/members.rb +++ b/lib/sof/members.rb @@ -17,12 +17,12 @@ module Sof if( occurence = @objects[object] ) #puts "reset level #{level} at #{occurence.level}" occurence.level = level if occurence.level > level - occurence.referenced = true + occurence.referenced = @counter + @counter = @counter + 1 return end - o = Occurence.new( object , @counter , level ) + o = Occurence.new( object , level ) @objects[object] = o - @counter = @counter + 1 attributes = attributes_for(object) attributes.each do |a| val = get_value( object , a) diff --git a/lib/sof/occurence.rb b/lib/sof/occurence.rb index 8fc99481..bcc39a24 100644 --- a/lib/sof/occurence.rb +++ b/lib/sof/occurence.rb @@ -1,12 +1,11 @@ module Sof class Occurence - def initialize object , number , level + def initialize object , level @object = object - @number = number @level = level end - attr_reader :object , :number + attr_reader :object attr_accessor :level , :referenced end diff --git a/lib/sof/writer.rb b/lib/sof/writer.rb index 7a31ee3a..4a41c892 100644 --- a/lib/sof/writer.rb +++ b/lib/sof/writer.rb @@ -20,9 +20,9 @@ module Sof raise "no object #{object}" unless occurence if(level > occurence.level ) #puts "level #{level} at #{occurence.level}" - return SimpleNode.new("*#{occurence.number}") + return SimpleNode.new("*#{occurence.referenced}") end - ref = occurence.referenced ? occurence.number : nil + ref = occurence.referenced if(object.respond_to? :to_sof_node) #mainly meant for arrays and hashes object.to_sof_node(self , level , ref ) else