Class: PutsUtils::PutsTable::Table
- Inherits:
-
Object
- Object
- PutsUtils::PutsTable::Table
- Defined in:
- lib/puts_utils/puts_table/table.rb
Instance Method Summary collapse
- #column(index) ⇒ Object
-
#initialize(headers, data) ⇒ Table
constructor
A new instance of Table.
- #rows ⇒ Object
Constructor Details
#initialize(headers, data) ⇒ Table
Returns a new instance of Table.
6 7 8 9 10 |
# File 'lib/puts_utils/puts_table/table.rb', line 6 def initialize(headers, data) @headers = headers || [] @data = data || [] @columns = {} end |
Instance Method Details
#column(index) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/puts_utils/puts_table/table.rb', line 16 def column(index) key = index.to_s.to_sym return @columns[key] if @columns.key?(key) @columns[key] = rows.map { |r| r[index] } end |
#rows ⇒ Object
12 13 14 |
# File 'lib/puts_utils/puts_table/table.rb', line 12 def rows @rows ||= [@headers] + @data end |