Class: Nanoc::Telemetry::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/nanoc/telemetry/table.rb

Instance Method Summary collapse

Constructor Details

#initialize(rows) ⇒ Table

Returns a new instance of Table



5
6
7
# File 'lib/nanoc/telemetry/table.rb', line 5

def initialize(rows)
  @rows = rows
end

Instance Method Details

#to_sObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/nanoc/telemetry/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)
    lines.concat(@rows.drop(1).map { |r| row_to_s(r, column_lengths) })
  end.join("\n")
end