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) ⇒ Boolean
Compares this model with another object.
-
#children ⇒ Array<Table, DocString>
Returns the model objects that are children of this model.
-
#initialize(source_text = nil) ⇒ Step
constructor
Creates a new Step object and, if source_text is provided, populates the object.
-
#inspect(verbose: false) ⇒ String
See ‘Object#inspect`.
-
#to_s ⇒ String
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.
31 32 33 |
# File 'lib/cuke_modeler/models/step.rb', line 31 def initialize(source_text = nil) super end |
Instance Attribute Details
#block ⇒ Object
The step’s passed block
18 19 20 |
# File 'lib/cuke_modeler/models/step.rb', line 18 def block @block end |
#keyword ⇒ Object
The step’s keyword
12 13 14 |
# File 'lib/cuke_modeler/models/step.rb', line 12 def keyword @keyword end |
#text ⇒ Object
The base text of the step
15 16 17 |
# File 'lib/cuke_modeler/models/step.rb', line 15 def text @text end |
Instance Method Details
#==(other) ⇒ Boolean
Compares this model with another object. Returns true if the two objects have the same base text, table, and doc string and false otherwise.
43 44 45 46 47 48 49 |
# File 'lib/cuke_modeler/models/step.rb', line 43 def ==(other) return false unless other.is_a?(CukeModeler::Step) text_matches?(other) && table_matches?(other) && doc_string_matches?(other) end |
#children ⇒ Array<Table, DocString>
Returns the model objects that are children of this model. For a Step model, these would be any associated Table or DocString models.
58 59 60 |
# File 'lib/cuke_modeler/models/step.rb', line 58 def children block ? [block] : [] end |
#inspect(verbose: false) ⇒ String
See ‘Object#inspect`. Returns some basic information about the object, including its class, object ID, and its most meaningful attribute. For a Step model, this will be the text of the step. If verbose is true, provides default Ruby inspection behavior instead.
89 90 91 92 93 |
# File 'lib/cuke_modeler/models/step.rb', line 89 def inspect(verbose: false) return super if verbose "#{super.chop} @text: #{@text.inspect}>" end |
#to_s ⇒ String
Returns a string representation of this model. For a Step model, this will be Gherkin text that is equivalent to the step being modeled.
69 70 71 72 73 74 |
# File 'lib/cuke_modeler/models/step.rb', line 69 def to_s text = "#{keyword} #{self.text}" text << "\n#{block.to_s.split("\n").collect { |line| " #{line}" }.join("\n")}" if block text end |