Class: Flare::Util::PrettyTable::Table

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

Instance Method Summary collapse

Constructor Details

#initializeTable

Returns a new instance of Table.



10
11
12
# File 'lib/flare/util/pretty_table/table.rb', line 10

def initialize
  @rows = []
end

Instance Method Details

#add_row(row) ⇒ Object



14
15
16
# File 'lib/flare/util/pretty_table/table.rb', line 14

def add_row(row)
  @rows << row
end

#max_column_widthsObject



25
26
27
28
29
30
31
32
33
# File 'lib/flare/util/pretty_table/table.rb', line 25

def max_column_widths
  widths = []
  @rows.each do |row|
    row.columns.each_with_index do |column, index|
      widths[index] = [column.width, (widths[index] || 0)].max
    end
  end
  widths
end

#prettifyObject



18
19
20
21
22
23
# File 'lib/flare/util/pretty_table/table.rb', line 18

def prettify
  column_widths = max_column_widths
  @rows \
    .map {|row| row.prettify(column_widths) } \
    .join("\n")
end