class Saga::Document
Attributes
definitions[RW]
introduction[RW]
stories[RW]
title[RW]
Public Class Methods
new()
click to toggle source
# File lib/saga/document.rb, line 5 def initialize @title = '' @introduction = [] @authors = [] @stories = {} @definitions = {} end
Public Instance Methods
_autofill_ids(stories, unused_ids)
click to toggle source
# File lib/saga/document.rb, line 71 def _autofill_ids(stories, unused_ids) stories.each do |story| story[:id] ||= unused_ids.shift _autofill_ids(story[:stories], unused_ids) if story[:stories] end end
_binding()
click to toggle source
# File lib/saga/document.rb, line 36 def _binding binding end
autofill_ids()
click to toggle source
# File lib/saga/document.rb, line 78 def autofill_ids unused_ids = unused_ids(length - used_ids.length) stories.each do |_section, data| _autofill_ids(data, unused_ids) end end
copy_story(story)
click to toggle source
# File lib/saga/document.rb, line 13 def copy_story(story) copied = {} %i[id iteration status estimate description].each do |attribute| copied[attribute] = story[attribute] if story[attribute] end; copied end
empty?()
click to toggle source
# File lib/saga/document.rb, line 67 def empty? length == 0 end
flatten_stories(stories)
click to toggle source
# File lib/saga/document.rb, line 20 def flatten_stories(stories) stories_as_flat_list = [] 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
length()
click to toggle source
# File lib/saga/document.rb, line 63 def length stories_as_flat_list.length end
stories_as_flat_list()
click to toggle source
# File lib/saga/document.rb, line 32 def stories_as_flat_list flatten_stories(stories.values) end
unused_ids(limit)
click to toggle source
# File lib/saga/document.rb, line 53 def unused_ids(limit) position = 1 used_ids = used_ids() (1..limit).map do while used_ids.include?(position) do position += 1 end used_ids << position position end end
used_ids()
click to toggle source
# File lib/saga/document.rb, line 40 def used_ids @stories.values.each_with_object([]) do |stories, ids| stories.each do |story| ids << story[:id] next unless story[:stories] story[:stories].each do |nested| ids << nested[:id] end end end.compact end