Sha256: dac7bc710a7b04260ceb40dc6ef3b24ddf82bae19f42db1bd56719d4e7651404
Contents?: true
Size: 868 Bytes
Versions: 3
Compression:
Stored size: 868 Bytes
Contents
# frozen_string_literal: true module DDTelemetry class Table def initialize(rows) @rows = rows end 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 private def row_to_s(row, column_lengths) values = row.zip(column_lengths).map { |text, length| text.rjust(length) } values[0] + ' │ ' + values[1..-1].join(' ') end def separator(column_lengths) (+'').tap do |s| s << '─' * column_lengths[0] s << '─┼─' s << column_lengths[1..-1].map { |l| '─' * l }.join('───') end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
ddtelemetry-1.0.0a3 | lib/ddtelemetry/table.rb |
ddtelemetry-1.0.0a2 | lib/ddtelemetry/table.rb |
ddtelemetry-1.0.0a1 | lib/ddtelemetry/table.rb |