Class: Saga::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/saga/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDocument

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

#authorsObject

Returns the value of attribute authors.



3
4
5
# File 'lib/saga/document.rb', line 3

def authors
  @authors
end

#definitionsObject

Returns the value of attribute definitions.



3
4
5
# File 'lib/saga/document.rb', line 3

def definitions
  @definitions
end

#introductionObject

Returns the value of attribute introduction.



3
4
5
# File 'lib/saga/document.rb', line 3

def introduction
  @introduction
end

#storiesObject

Returns the value of attribute stories.



3
4
5
# File 'lib/saga/document.rb', line 3

def stories
  @stories
end

#titleObject

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

#_bindingObject



24
25
26
# File 'lib/saga/document.rb', line 24

def _binding
  binding
end

#autofill_idsObject



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

Returns:

  • (Boolean)


46
47
48
# File 'lib/saga/document.rb', line 46

def empty?
  length == 0
end

#lengthObject



42
43
44
# File 'lib/saga/document.rb', line 42

def length
  stories_as_flat_list.length
end

#stories_as_flat_listObject



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_idsObject



28
29
30
# File 'lib/saga/document.rb', line 28

def used_ids
  stories_as_flat_list.map{ |story| story[:id] }.compact
end