Class: CukeModeler::Step

Inherits:
Model
  • Object
show all
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

Attributes included from Parsed

#parsing_data

Attributes included from Sourceable

#source_column, #source_line

Attributes included from Nested

#parent_model

Instance Method Summary collapse

Methods included from Parsing

dialects, parse_text

Methods included from Containing

#each, #each_descendant, #each_model

Methods included from Nested

#get_ancestor

Constructor Details

#initialize(source_text = nil) ⇒ Step

Creates a new Step object and, if source_text is provided, populates the object.

Examples:

Step.new
Step.new("Given a step")

Parameters:

  • source_text (String) (defaults to: nil)

    The Gherkin text that will be used to populate the model

Raises:

  • (ArgumentError)

    If source_text is not a String



31
32
33
# File 'lib/cuke_modeler/models/step.rb', line 31

def initialize(source_text = nil)
  super
end

Instance Attribute Details

#blockObject

The step’s passed block



18
19
20
# File 'lib/cuke_modeler/models/step.rb', line 18

def block
  @block
end

#keywordObject

The step’s keyword



12
13
14
# File 'lib/cuke_modeler/models/step.rb', line 12

def keyword
  @keyword
end

#textObject

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.

Examples:

step_1 == step_2

Parameters:

  • other (Object)

    The object to compare this model with

Returns:

  • (Boolean)

    Whether the two objects are equivalent



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

#childrenArray<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.

Examples:

step.children

Returns:



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.

Examples:

step.inspect
step.inspect(verbose: true)

Parameters:

  • verbose (Boolean) (defaults to: false)

    Whether or not to return the full details of the object. Defaults to false.

Returns:

  • (String)

    A string representation of this model



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_sString

Returns a string representation of this model. For a Step model, this will be Gherkin text that is equivalent to the step being modeled.

Examples:

step.to_s

Returns:

  • (String)

    A string representation of this model



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