Class: CukeModeler::Table

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

Overview

A class modeling a step’s table.

Instance Attribute Summary collapse

Attributes included from Sourceable

#source_column, #source_line

Attributes included from Parsed

#parsing_data

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

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

Examples:

Table.new
Table.new("|value_1|value_2|\n|value_3|value_4|")

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



25
26
27
28
29
# File 'lib/cuke_modeler/models/table.rb', line 25

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

  super(source_text)
end

Instance Attribute Details

#rowsObject

The row models that make up the table



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

def rows
  @rows
end

Instance Method Details

#childrenArray<Row>

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

Examples:

table.children

Returns:

  • (Array<Row>)

    A collection of child models



38
39
40
# File 'lib/cuke_modeler/models/table.rb', line 38

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

Examples:

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



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

def inspect(verbose: false)
  return super(verbose: verbose) if verbose

  row_output = @rows&.collect { |row| row.cells.collect(&:value) }

  "#{super.chop} @rows: #{row_output.inspect}>"
end

#to_sString

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

Examples:

table.to_s

Returns:

  • (String)

    A string representation of this model



49
50
51
# File 'lib/cuke_modeler/models/table.rb', line 49

def to_s
  rows.empty? ? '' : rows.collect { |row| row_output_string(row) }.join("\n")
end