Class: CukeModeler::Step
- Includes:
- Parsed, Parsing, Sourceable
- Defined in:
- lib/cuke_modeler/models/step.rb
Overview
A class modeling a single step of a background, scenario, or outline.
Instance Attribute Summary collapse
-
#block ⇒ Object
The step’s passed block.
-
#keyword ⇒ Object
The step’s keyword.
-
#text ⇒ Object
The base text of the step.
Attributes included from Parsed
Attributes included from Sourceable
Attributes included from Nested
Instance Method Summary collapse
-
#==(other) ⇒ Object
Returns true if the two steps have the same base text (i.e. minus any keyword, table, or doc string and false otherwise..
-
#children ⇒ Object
Returns the model objects that belong to this model.
-
#initialize(source_text = nil) ⇒ Step
constructor
Creates a new Step object and, if source_text is provided, populates the object.
-
#to_s ⇒ Object
Returns a string representation of this model.
Methods included from Parsing
Methods included from Containing
#each, #each_descendant, #each_model
Methods included from Nested
Constructor Details
#initialize(source_text = nil) ⇒ Step
Creates a new Step object and, if source_text is provided, populates the object.
24 25 26 27 28 29 30 31 |
# File 'lib/cuke_modeler/models/step.rb', line 24 def initialize(source_text = nil) super(source_text) return unless source_text parsed_step_data = parse_source(source_text) populate_step(self, parsed_step_data) end |
Instance Attribute Details
#block ⇒ Object
The step’s passed block
19 20 21 |
# File 'lib/cuke_modeler/models/step.rb', line 19 def block @block end |
#keyword ⇒ Object
The step’s keyword
13 14 15 |
# File 'lib/cuke_modeler/models/step.rb', line 13 def keyword @keyword end |
#text ⇒ Object
The base text of the step
16 17 18 |
# File 'lib/cuke_modeler/models/step.rb', line 16 def text @text end |
Instance Method Details
#==(other) ⇒ Object
Returns true if the two steps have the same base text (i.e. minus any keyword, table, or doc string and false otherwise.
35 36 37 38 39 40 41 |
# File 'lib/cuke_modeler/models/step.rb', line 35 def ==(other) return false unless other.is_a?(CukeModeler::Step) text_matches?(other) && table_matches?(other) && doc_string_matches?(other) end |
#children ⇒ Object
Returns the model objects that belong to this model.
44 45 46 |
# File 'lib/cuke_modeler/models/step.rb', line 44 def children block ? [block] : [] end |
#to_s ⇒ Object
Returns a string representation of this model. For a step model, this will be Gherkin text that is equivalent to the step being modeled.
50 51 52 53 54 55 |
# File 'lib/cuke_modeler/models/step.rb', line 50 def to_s text = "#{keyword} #{self.text}" text << "\n#{block.to_s.split("\n").collect { |line| " #{line}" }.join("\n")}" if block text end |