class Saga::Parser
Attributes
document[RW]
Public Class Methods
new()
click to toggle source
# File lib/saga/parser.rb, line 5 def initialize @tokenizer = ::Saga::Tokenizer.new(self) @document = ::Saga::Document.new self.current_section = :title @current_header = '' end
parse(input)
click to toggle source
# File lib/saga/parser.rb, line 72 def self.parse(input) parser = new parser.parse(input) end
Public Instance Methods
current_section=(section)
click to toggle source
# File lib/saga/parser.rb, line 12 def current_section=(section) @current_section = section @tokenizer.current_section = section end
handle_definition(definition)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/saga/parser.rb, line 17 def parse(input) @tokenizer.process(input) @document end