Class: CukeModeler::Row

Inherits:
Model
  • Object
show all
Includes:
Parsed, Parsing, Sourceable
Defined in:
lib/cuke_modeler/models/row.rb

Overview

A class modeling a single row of a step table or example table.

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) ⇒ Row

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

Examples:

Row.new
Row.new('|value_1|value_2|')

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



24
25
26
27
28
# File 'lib/cuke_modeler/models/row.rb', line 24

def initialize(source_text = nil)
  @cells = []

  super
end

Instance Attribute Details

#cellsObject

The cell models that make up the row



11
12
13
# File 'lib/cuke_modeler/models/row.rb', line 11

def cells
  @cells
end

Instance Method Details

#childrenArray<Cell>

Returns the model objects that are children of this model. For a Row model, these would be any associated Cell models.

Examples:

row.children

Returns:

  • (Array<Cell>)

    A collection of child models



37
38
39
# File 'lib/cuke_modeler/models/row.rb', line 37

def children
  @cells
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 Row model, this will be the cells of the row. If verbose is true, provides default Ruby inspection behavior instead.

Examples:

row.inspect
row.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



67
68
69
70
71
72
73
# File 'lib/cuke_modeler/models/row.rb', line 67

def inspect(verbose: false)
  return super if verbose

  cell_output = @cells&.collect(&:value)

  "#{super.chop} @cells: #{cell_output.inspect}>"
end

#to_sString

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

Examples:

row.to_s

Returns:

  • (String)

    A string representation of this model



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

def to_s
  text_cells = cells.map(&:to_s)

  "| #{text_cells.join(' | ')} |"
end