lib/saga/document.rb in saga-0.9.1 vs lib/saga/document.rb in saga-0.10.0

- old
+ new

@@ -10,18 +10,33 @@ @authors = [] @stories = ActiveSupport::OrderedHash.new @definitions = ActiveSupport::OrderedHash.new end - def stories_as_flat_list + def copy_story(story) + copied = {} + [:id, :iteration, :status, :estimate, :description].each do |attribute| + copied[attribute] = story[attribute] if story[attribute] + end; copied + end + + def flatten_stories(stories) 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] + stories.flatten.each do |story| + if story[:stories] + stories_as_flat_list << copy_story(story) + stories_as_flat_list.concat(story[:stories]) + else + stories_as_flat_list << story + end end; stories_as_flat_list end + def stories_as_flat_list + flatten_stories(stories.values) + end + def _binding binding end def used_ids @@ -51,13 +66,22 @@ def empty? length == 0 end + def _autofill_ids(stories, unused_ids) + stories.each do |story| + story[:id] ||= unused_ids.shift + if story[:stories] + _autofill_ids(story[:stories], unused_ids) + end + end + end + def autofill_ids unused_ids = unused_ids(length - used_ids.length) - stories_as_flat_list.each do |story| - story[:id] ||= unused_ids.shift + stories.each do |section, data| + _autofill_ids(data, unused_ids) end end end end \ No newline at end of file