Class: Flare::Util::PrettyTable::Table
- Inherits:
-
Object
- Object
- Flare::Util::PrettyTable::Table
- Defined in:
- lib/flare/util/pretty_table/table.rb
Instance Method Summary collapse
- #add_row(row) ⇒ Object
-
#initialize ⇒ Table
constructor
A new instance of Table.
- #max_column_widths ⇒ Object
- #prettify ⇒ Object
Constructor Details
#initialize ⇒ Table
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_widths ⇒ Object
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 |
#prettify ⇒ Object
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 |