class CukeModeler::Table
A class modeling a step's table.
Attributes
rows[RW]
The row models that make up the table
Public Class Methods
new(source_text = nil)
click to toggle source
Creates a new Table
object and, if source_text is provided, populates the object.
Calls superclass method
CukeModeler::Model::new
# File lib/cuke_modeler/models/table.rb, line 17 def initialize(source_text = nil) @rows = [] super(source_text) return unless source_text parsed_table_data = parse_source(source_text) populate_table(self, parsed_table_data) end
Public Instance Methods
children()
click to toggle source
Returns the model objects that belong to this model.
# File lib/cuke_modeler/models/table.rb, line 29 def children rows end
to_s()
click to toggle source
Returns a string representation of this model. For a table model, this will be Gherkin text that is equivalent to the table being modeled.
# File lib/cuke_modeler/models/table.rb, line 35 def to_s rows.empty? ? '' : rows.collect { |row| row_output_string(row) }.join("\n") end
Private Instance Methods
determine_buffer_size(index)
click to toggle source
# File lib/cuke_modeler/models/table.rb, line 65 def determine_buffer_size(index) rows.collect { |row| row.cells[index].to_s.length }.max || 0 end
parse_source(source_text)
click to toggle source
# File lib/cuke_modeler/models/table.rb, line 43 def parse_source(source_text) base_file_string = "# language: #{Parsing.dialect} #{dialect_feature_keyword}: #{dialect_scenario_keyword}: #{dialect_step_keyword} step\n" source_text = base_file_string + source_text parsed_file = Parsing.parse_text(source_text, 'cuke_modeler_stand_alone_table.feature') parsed_file['feature']['elements'].first['steps'].first['table'] end
row_output_string(row)
click to toggle source
# File lib/cuke_modeler/models/table.rb, line 55 def row_output_string(row) row_text = '|' row.cells.count.times do |count| row_text << " #{row.cells[count].to_s.ljust(determine_buffer_size(count))} |" end row_text end