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)

  return unless source_text

  parsed_step_data = parse_source(source_text)
  populate_step(self, parsed_step_data)
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) ⇒ 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

#childrenObject

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


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