Class: Strut::Parser
- Inherits:
-
Object
- Object
- Strut::Parser
- Defined in:
- lib/strut/parser.rb
Constant Summary collapse
- X_SCENARIO_PREFIX =
"x-scenario-"
Instance Method Summary collapse
- #append_import_command ⇒ Object
- #extract_scenarios(node) ⇒ Object
- #extract_scenarios_for_children(scenario_number, node, path_stack) ⇒ Object
- #extract_scenarios_for_node(node_name, node, path_stack) ⇒ Object
-
#initialize(namespace) ⇒ Parser
constructor
A new instance of Parser.
- #parse(yaml) ⇒ Object
Constructor Details
#initialize(namespace) ⇒ Parser
Returns a new instance of Parser.
12 13 14 15 16 17 18 19 |
# File 'lib/strut/parser.rb', line 12 def initialize(namespace) @namespace = namespace @command_factory = SlimCommandFactory.new @document_builder = DocumentBuilder.new @interaction_factory = InteractionFactory.new @scenario_builder = ScenarioBuilder.new(@document_builder, @command_factory) @scenario_number = 1 end |
Instance Method Details
#append_import_command ⇒ Object
28 29 30 31 32 |
# File 'lib/strut/parser.rb', line 28 def append_import_command = CommandMetadata.new(1) import_command = @command_factory.make_import_command(, @namespace) @document_builder.append_command(import_command) end |
#extract_scenarios(node) ⇒ Object
34 35 36 37 |
# File 'lib/strut/parser.rb', line 34 def extract_scenarios(node) wrapped_node = {"value" => node, "line" => 0} extract_scenarios_for_node("", wrapped_node, []) end |
#extract_scenarios_for_children(scenario_number, node, path_stack) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/strut/parser.rb', line 49 def extract_scenarios_for_children(scenario_number, node, path_stack) return unless node.respond_to?(:each_pair) node.each_pair do |child_node_name, child_node| next_path_stack = path_stack + [child_node_name] extract_scenarios_for_node(child_node_name.to_s, child_node, next_path_stack) end end |
#extract_scenarios_for_node(node_name, node, path_stack) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/strut/parser.rb', line 39 def extract_scenarios_for_node(node_name, node, path_stack) if node_name.start_with?(X_SCENARIO_PREFIX) fixture = node_name.gsub(/^#{X_SCENARIO_PREFIX}/, "") interaction = @interaction_factory.make_interaction(path_stack) @scenario_number = @scenario_builder.extract_scenarios_for_interaction(@scenario_number, interaction, fixture, node) else extract_scenarios_for_children(@scenario_number, node["value"], path_stack) end end |
#parse(yaml) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/strut/parser.rb', line 21 def parse(yaml) parsed_yaml = Psych::parse_yaml(yaml) append_import_command extract_scenarios(parsed_yaml) @document_builder.document end |