Class: PutsUtils::PutsTable::Table

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

Instance Method Summary collapse

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

#rowsObject



12
13
14
# File 'lib/puts_utils/puts_table/table.rb', line 12

def rows
  @rows ||= [@headers] + @data
end