Class: DDMetrics::Table
- Inherits:
-
Object
- Object
- DDMetrics::Table
- Defined in:
- lib/ddmetrics/table.rb
Instance Method Summary collapse
-
#initialize(rows) ⇒ Table
constructor
A new instance of Table.
- #to_s ⇒ Object
Constructor Details
#initialize(rows) ⇒ Table
Returns a new instance of Table.
5 6 7 |
# File 'lib/ddmetrics/table.rb', line 5 def initialize(rows) @rows = rows end |
Instance Method Details
#to_s ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ddmetrics/table.rb', line 9 def to_s columns = @rows.transpose column_lengths = columns.map { |c| c.map(&:size).max } [].tap do |lines| lines << row_to_s(@rows[0], column_lengths) lines << separator(column_lengths) rows = sort_rows(@rows.drop(1)) lines.concat(rows.map { |r| row_to_s(r, column_lengths) }) end.join("\n") end |