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_line

Attributes included from Nested

#parent_model

Instance Method Summary collapse

Methods included from Parsing

dialects, parse_text

Methods included from Containing

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



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)

  if source_text
    parsed_step_data = parse_source(source_text)
    populate_step(self, parsed_step_data)
  end
end

Instance Attribute Details

#blockObject

The step’s passed block



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

def block
  @block
end

#keywordObject

The step’s keyword



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

def keyword
  @keyword
end

#textObject

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_step) ⇒ 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
# File 'lib/cuke_modeler/models/step.rb', line 35

def ==(other_step)
  return false unless other_step.respond_to?(:text)

  text == other_step.text
end

#childrenObject

Returns the model objects that belong to this model.



42
43
44
# File 'lib/cuke_modeler/models/step.rb', line 42

def children
  block ? [block] : []
end

#to_sObject

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



48
49
50
51
52
53
# File 'lib/cuke_modeler/models/step.rb', line 48

def to_s
  text = "#{keyword} #{self.text}"
  text << "\n" + block.to_s.split("\n").collect { |line| "  #{line}" }.join("\n") if block

  text
end