Class: Saga::Parser
- Inherits:
-
Object
- Object
- Saga::Parser
- Defined in:
- lib/saga/parser.rb
Instance Attribute Summary collapse
-
#document ⇒ Object
Returns the value of attribute document.
Class Method Summary collapse
Instance Method Summary collapse
- #current_section=(section) ⇒ Object
- #handle_author(author) ⇒ Object
- #handle_definition(definition) ⇒ Object
- #handle_notes(notes) ⇒ Object
- #handle_story(story) ⇒ Object
- #handle_string(string) ⇒ Object
- #handle_substory(story) ⇒ Object
-
#initialize ⇒ Parser
constructor
A new instance of Parser.
- #parse(input) ⇒ Object
Constructor Details
Instance Attribute Details
#document ⇒ Object
Returns the value of attribute document.
3 4 5 |
# File 'lib/saga/parser.rb', line 3 def document @document end |
Class Method Details
.parse(input) ⇒ Object
71 72 73 74 |
# File 'lib/saga/parser.rb', line 71 def self.parse(input) parser = new parser.parse(input) end |
Instance Method Details
#current_section=(section) ⇒ Object
12 13 14 15 |
# File 'lib/saga/parser.rb', line 12 def current_section=(section) @current_section = section @tokenizer.current_section = section end |
#handle_author(author) ⇒ Object
22 23 24 |
# File 'lib/saga/parser.rb', line 22 def () @document. << end |
#handle_definition(definition) ⇒ Object
47 48 49 50 51 |
# File 'lib/saga/parser.rb', line 47 def handle_definition(definition) self.current_section = :definitions @document.definitions[@current_header] ||= [] @document.definitions[@current_header] << definition end |
#handle_notes(notes) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/saga/parser.rb', line 38 def handle_notes(notes) story = @document.stories[@current_header][-1] if @current_section == :story story[:stories][-1][:notes] = notes else story[:notes] = notes end end |
#handle_story(story) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/saga/parser.rb', line 26 def handle_story(story) story[:type] = 'story' unless story[:type] self.current_section = :stories @document.stories[@current_header] ||= [] @document.stories[@current_header] << story end |
#handle_string(string) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/saga/parser.rb', line 53 def handle_string(string) return if string.strip == '' if string.strip == 'USER STORIES' self.current_section = :stories return @current_section end if @current_section == :title @document.title = string.gsub(/^requirements/i, '').strip self.current_section = :introduction elsif @current_section == :introduction @document.introduction << string else @current_header = string.strip end end |
#handle_substory(story) ⇒ Object
33 34 35 36 |
# File 'lib/saga/parser.rb', line 33 def handle_substory(story) story[:type] = 'substory' handle_story(story) end |
#parse(input) ⇒ Object
17 18 19 20 |
# File 'lib/saga/parser.rb', line 17 def parse(input) @tokenizer.process(input) @document end |