Class: CukeModeler::Table
- Includes:
- Parsed, Parsing, Sourceable
- Defined in:
- lib/cuke_modeler/models/table.rb
Overview
A class modeling a step’s table.
Instance Attribute Summary collapse
-
#rows ⇒ Object
The row models that make up the table.
Attributes included from Sourceable
Attributes included from Parsed
Attributes included from Nested
Instance Method Summary collapse
-
#children ⇒ Array<Row>
Returns the model objects that are children of this model.
-
#initialize(source_text = nil) ⇒ Table
constructor
Creates a new Table object and, if source_text is provided, populates the object.
-
#inspect(verbose: false) ⇒ String
See ‘Object#inspect`.
-
#to_s ⇒ String
Returns a string representation of this model.
Methods included from Parsing
Methods included from Containing
#each, #each_descendant, #each_model
Methods included from Nested
Constructor Details
#initialize(source_text = nil) ⇒ Table
Creates a new Table object and, if source_text is provided, populates the object.
25 26 27 28 29 |
# File 'lib/cuke_modeler/models/table.rb', line 25 def initialize(source_text = nil) @rows = [] super end |
Instance Attribute Details
#rows ⇒ Object
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
#children ⇒ Array<Row>
Returns the model objects that are children of this model. For a Table model, these would be any associated Row 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.
66 67 68 69 70 71 72 |
# File 'lib/cuke_modeler/models/table.rb', line 66 def inspect(verbose: false) return super if verbose row_output = @rows&.collect { |row| row.cells.collect(&:value) } "#{super.chop} @rows: #{row_output.inspect}>" end |
#to_s ⇒ String
Returns a string representation of this model. For a Table model, this will be Gherkin text that is equivalent to the table being modeled.
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 |