Sha256: acf76e8e4420dac71d7d673eabda20efb94dad32332eb86b636f06789cf6aff5
Contents?: true
Size: 692 Bytes
Versions: 6
Compression:
Stored size: 692 Bytes
Contents
module Kuby module Utils class Table attr_reader :headers, :rows def initialize(headers, rows) @headers = headers @rows = rows end def to_s [headers, *rows].map { |vals| make_row(vals) }.join("\n") end private def make_row(values) columns = values.each_with_index.map do |value, idx| col_width = col_width_at(idx) + 2 value.ljust(col_width, ' ') end columns.join end def col_width_at(idx) col_widths[idx] ||= [headers[idx].size, *rows.map { |r| r[idx].size }].max end def col_widths @col_widths ||= {} end end end end
Version data entries
6 entries across 6 versions & 1 rubygems