Class: Gauge::Row

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

Overview

Holds a row of a table.

Instance Method Summary collapse

Constructor Details

#initialize(columns, values) ⇒ Row

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 Row.



70
71
72
73
# File 'lib/table.rb', line 70

def initialize(columns, values)
  @values = values
  @columns = columns
end

Instance Method Details

#[](index) ⇒ string

Gets the row cell.

Examples:

row[0] => 'value'
row['column'] => 'value'
row[i] => nil # when index is out of range

Parameters:

  • index

    Either cell index, or Column name.

Returns:

  • (string)

    value of the row cell



82
83
84
85
86
# File 'lib/table.rb', line 82

def [](index)
  return @values[index] if index.is_a?(Integer)
  columns_index = @columns.index(index)
  columns_index.nil? ? nil : @values[columns_index]
end