Class: Gauge::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/table.rb

Overview

Holds a table definition. This corresponds to a markdown table defined in the .spec files.

Instance Method Summary collapse

Constructor Details

#initialize(protoTable) ⇒ Table

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Table.



23
24
25
26
27
28
29
# File 'lib/table.rb', line 23

def initialize(protoTable)
  @columns = protoTable.headers.cells
  @rows = []
  protoTable.rows.each do |row|
      @rows.push Row.new(@columns, row.cells)
  end
end

Instance Method Details

#[](index) ⇒ Hash, string[]

Gets the table data.

Examples:

table[0] => {"Col1" => "Row1.Cell1", "Col2" => "Row2.Col1", ...}
table[i] => nil # when index is out of range
table["Col1"] => ["Row1.Cell1", "Row1.Cell1", ...]
table["Invalid_Col_Name"] => nil

Parameters:

  • index

    Either row index, or Column name.

Returns:

  • (Hash)

    When an integer index is passed. Values correspond to a the row in the table with the index.

  • (string[])

    When a string key is passed. Values correspond to the respective cells in a row, matching the index of value in Column headers.



53
54
55
56
# File 'lib/table.rb', line 53

def [](index)
  return @rows[index] if index.is_a?(Integer)
  column_values_as_array(index)
end

#columnsstring[]

Gets the column headers of the table

Returns:

  • (string[])


33
34
35
# File 'lib/table.rb', line 33

def columns
  @columns
end

#rowsstring[][]

Gets the rows of the table. The rows are two dimensional arrays.

Returns:

  • (string[][])


39
40
41
# File 'lib/table.rb', line 39

def rows
  @rows
end