lib/saga/document.rb in saga-0.7.1 vs lib/saga/document.rb in saga-0.8.0

- old
+ new

@@ -10,14 +10,26 @@ @authors = [] @stories = ActiveSupport::OrderedHash.new @definitions = ActiveSupport::OrderedHash.new end + def stories_as_flat_list + stories_as_flat_list = [] + stories.values.flatten.each do |story| + stories_as_flat_list << story + stories_as_flat_list.concat(story[:stories]) if story[:stories] + end; stories_as_flat_list + end + def used_ids @stories.values.inject([]) do |ids, stories| - ids.concat stories.map { |story| story[:id] } - ids + stories.each do |story| + ids << story[:id] + story[:stories].each do |nested| + ids << nested[:id] + end if story[:stories] + end; ids end.compact end def unused_ids(limit) position = 1 @@ -28,22 +40,20 @@ position end end def length - stories.inject(0) { |total, (_, stories)| total + stories.length } + stories_as_flat_list.length end def empty? length == 0 end def autofill_ids unused_ids = unused_ids(length - used_ids.length) - stories.each do |_, stories| - stories.each do |story| - story[:id] ||= unused_ids.shift - end + stories_as_flat_list.each do |story| + story[:id] ||= unused_ids.shift end end end end \ No newline at end of file