class Smartdown::Parser::ScenarioSetInterpreter
Public Class Methods
new(scenario_string)
click to toggle source
# File lib/smartdown/parser/scenario_set_interpreter.rb, line 9 def initialize(scenario_string) @scenario_lines = scenario_string.split("\n") end
Public Instance Methods
description()
click to toggle source
# File lib/smartdown/parser/scenario_set_interpreter.rb, line 27 def description description_lines.map do |description_line| description_line[1..-1].strip end.join(";") end
description_lines()
click to toggle source
# File lib/smartdown/parser/scenario_set_interpreter.rb, line 23 def description_lines @scenario_lines.select{ |line| line.start_with?("#") } end
exact_markers()
click to toggle source
# File lib/smartdown/parser/scenario_set_interpreter.rb, line 68 def exact_markers if has_exact_markers? marker_line = @scenario_lines.find { |line| line.match(/(exact markers:|exact marker:)/) } comma_sperated_markers = marker_line.slice(marker_line.index(":") + 1, marker_line.size) comma_sperated_markers.split(',').map(&:strip) else [] end end
first_question()
click to toggle source
# File lib/smartdown/parser/scenario_set_interpreter.rb, line 42 def first_question @scenario_lines.index { |line| line.match(/(\s\s\S*:)|(- \S*:)/) } end
has_exact_markers?()
click to toggle source
# File lib/smartdown/parser/scenario_set_interpreter.rb, line 54 def has_exact_markers? @scenario_lines.any? { |line| line.match(/(exact markers:|exact marker:)/) } end
has_markers?()
click to toggle source
# File lib/smartdown/parser/scenario_set_interpreter.rb, line 50 def has_markers? @scenario_lines.any? { |line| line.match(/(has markers:|has marker:)/) } end
last_question()
click to toggle source
# File lib/smartdown/parser/scenario_set_interpreter.rb, line 38 def last_question @scenario_lines.rindex { |line| line.match(/(\s\s\S*:)|(- \S*:)/) } end
markers()
click to toggle source
# File lib/smartdown/parser/scenario_set_interpreter.rb, line 58 def markers if has_markers? marker_line = @scenario_lines.find { |line| line.match(/(has markers:|has marker:)/) } comma_sperated_markers = marker_line.slice(marker_line.index(":") + 1, marker_line.size) comma_sperated_markers.split(',').map(&:strip) else [] end end
outcome()
click to toggle source
# File lib/smartdown/parser/scenario_set_interpreter.rb, line 46 def outcome @scenario_lines[last_question + 1] end
question_groups()
click to toggle source
# File lib/smartdown/parser/scenario_set_interpreter.rb, line 33 def question_groups question_pages = group_questions_by_page(@scenario_lines[first_question..last_question]) question_groups = question_pages.map { |question_page| interpret_question_page(question_page) } end
scenario()
click to toggle source
# File lib/smartdown/parser/scenario_set_interpreter.rb, line 13 def scenario Smartdown::Model::Scenarios::Scenario.new( description, question_groups, outcome, markers, exact_markers ) end
Private Instance Methods
group_questions_by_page(lines)
click to toggle source
# File lib/smartdown/parser/scenario_set_interpreter.rb, line 80 def group_questions_by_page(lines) result = [] lines.each do |scenario_line| if scenario_line.start_with?("-") result << [scenario_line[1..-1]] else result.last << scenario_line end end result end
interpret_question(question_string)
click to toggle source
# File lib/smartdown/parser/scenario_set_interpreter.rb, line 98 def interpret_question(question_string) name, answer = question_string.split(":").map(&:strip) Smartdown::Model::Scenarios::Question.new( name, answer, ) end
interpret_question_page(question_page)
click to toggle source
# File lib/smartdown/parser/scenario_set_interpreter.rb, line 92 def interpret_question_page(question_page) question_page.map { |question| interpret_question(question) } end