Class: Saga::Document
- Inherits:
-
Object
- Object
- Saga::Document
- Defined in:
- lib/saga/document.rb
Instance Attribute Summary collapse
-
#authors ⇒ Object
Returns the value of attribute authors.
-
#definitions ⇒ Object
Returns the value of attribute definitions.
-
#introduction ⇒ Object
Returns the value of attribute introduction.
-
#stories ⇒ Object
Returns the value of attribute stories.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #_autofill_ids(stories, unused_ids) ⇒ Object
- #_binding ⇒ Object
- #autofill_ids ⇒ Object
- #copy_story(story) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ Document
constructor
A new instance of Document.
- #length ⇒ Object
- #stories_as_flat_list ⇒ Object
- #unused_ids(limit) ⇒ Object
- #used_ids ⇒ Object
Constructor Details
#initialize ⇒ Document
Returns a new instance of Document.
5 6 7 8 9 10 11 |
# File 'lib/saga/document.rb', line 5 def initialize @title = '' @introduction = [] @authors = [] @stories = {} @definitions = {} end |
Instance Attribute Details
#authors ⇒ Object
Returns the value of attribute authors.
3 4 5 |
# File 'lib/saga/document.rb', line 3 def @authors end |
#definitions ⇒ Object
Returns the value of attribute definitions.
3 4 5 |
# File 'lib/saga/document.rb', line 3 def definitions @definitions end |
#introduction ⇒ Object
Returns the value of attribute introduction.
3 4 5 |
# File 'lib/saga/document.rb', line 3 def introduction @introduction end |
#stories ⇒ Object
Returns the value of attribute stories.
3 4 5 |
# File 'lib/saga/document.rb', line 3 def stories @stories end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/saga/document.rb', line 3 def title @title end |
Instance Method Details
#_autofill_ids(stories, unused_ids) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/saga/document.rb', line 50 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 ⇒ Object
24 25 26 |
# File 'lib/saga/document.rb', line 24 def _binding binding end |
#autofill_ids ⇒ Object
57 58 59 60 61 62 |
# File 'lib/saga/document.rb', line 57 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) ⇒ Object
13 14 15 16 17 18 |
# 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? ⇒ Boolean
46 47 48 |
# File 'lib/saga/document.rb', line 46 def empty? length == 0 end |
#length ⇒ Object
42 43 44 |
# File 'lib/saga/document.rb', line 42 def length stories_as_flat_list.length end |
#stories_as_flat_list ⇒ Object
20 21 22 |
# File 'lib/saga/document.rb', line 20 def stories_as_flat_list stories.values.flatten end |
#unused_ids(limit) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/saga/document.rb', line 32 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 ⇒ Object
28 29 30 |
# File 'lib/saga/document.rb', line 28 def used_ids stories_as_flat_list.map{ |story| story[:id] }.compact end |