class TerminalTable

Public Class Methods

new(attributes) click to toggle source
# File lib/winds-up-client.rb, line 10
def initialize attributes
        @rows = attributes[:rows]
end

Public Instance Methods

to_s() click to toggle source
# File lib/winds-up-client.rb, line 14
    def to_s
return "" if @rows.size == 0
widths = @rows.reduce(@rows[0].size.times.to_a.map { 0 } ) { |memo, row| memo.each_with_index.map { |item, i| [row.size > i ? row[i].size : 0, item].max } }
@rows.map do |row|
  row.each_with_index.map { |item, i| "#{item}#{" " * (widths[i] - item.size)}" }.join(" ")
end.join("\n")
    end