class CucumberAnalytics::Table

A class modeling the table of a Step.

Attributes

contents[RW]

The contents of the table

Deprecated

row_elements[RW]

The row elements that make up the table

Public Class Methods

new(source = nil) click to toggle source

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

# File lib/cucumber_analytics/table.rb, line 23
def initialize(source = nil)
  @contents = []
  @row_elements = []

  parsed_table = process_source(source)

  build_table(parsed_table) if parsed_table
end

Public Instance Methods

to_s() click to toggle source

Returns a gherkin representation of the table.

# File lib/cucumber_analytics/table.rb, line 33
def to_s
  row_elements.empty? ? '' : row_elements.collect { |row| row_output_string(row) }.join("\n")
end

Private Instance Methods

build_table(table) click to toggle source
# File lib/cucumber_analytics/table.rb, line 59
def build_table(table)
  populate_contents(table)
  populate_row_elements(table)
  populate_raw_element(table)
end
determine_buffer_size(index) click to toggle source
# File lib/cucumber_analytics/table.rb, line 85
def determine_buffer_size(index)
  row_elements.collect { |row| row.cells[index].length }.max || 0
end
parse_table(source_text) click to toggle source
# File lib/cucumber_analytics/table.rb, line 50
def parse_table(source_text)
  base_file_string = "Feature:\nScenario:\n* step\n"
  source_text = base_file_string + source_text

  parsed_file = Parsing::parse_text(source_text)

  parsed_file.first['elements'].first['steps'].first['rows']
end
populate_contents(table) click to toggle source
# File lib/cucumber_analytics/table.rb, line 65
def populate_contents(table)
  @contents = table.collect { |row| row['cells'] }
end
populate_row_elements(table) click to toggle source
# File lib/cucumber_analytics/table.rb, line 69
def populate_row_elements(table)
  table.each do |row|
    @row_elements << build_child_element(TableRow, row)
  end
end
process_source(source) click to toggle source
# File lib/cucumber_analytics/table.rb, line 41
def process_source(source)
  case
    when source.is_a?(String)
      parse_table(source)
    else
      source
  end
end
row_output_string(row) click to toggle source
# File lib/cucumber_analytics/table.rb, line 75
def row_output_string(row)
  row_text = '|'

  row.cells.count.times do |count|
    row_text << " #{row.cells[count].ljust(determine_buffer_size(count))} |"
  end

  row_text
end