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_nested_story(story) ⇒ Object
- #handle_notes(notes) ⇒ Object
- #handle_story(story) ⇒ Object
- #handle_string(string) ⇒ 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
72 73 74 75 |
# File 'lib/saga/parser.rb', line 72 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
48 49 50 51 52 |
# File 'lib/saga/parser.rb', line 48 def handle_definition(definition) self.current_section = :definitions @document.definitions[@current_header] ||= [] @document.definitions[@current_header] << definition end |
#handle_nested_story(story) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/saga/parser.rb', line 32 def handle_nested_story(story) self.current_section = :story parent = @document.stories[@current_header][-1] parent[:stories] ||= [] parent[:stories] << story end |
#handle_notes(notes) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/saga/parser.rb', line 39 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 |
# File 'lib/saga/parser.rb', line 26 def handle_story(story) self.current_section = :stories @document.stories[@current_header] ||= [] @document.stories[@current_header] << story end |
#handle_string(string) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/saga/parser.rb', line 54 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 |
#parse(input) ⇒ Object
17 18 19 20 |
# File 'lib/saga/parser.rb', line 17 def parse(input) @tokenizer.process(input) @document end |