Class: TerminalTable
- Inherits:
-
Object
- Object
- TerminalTable
- Defined in:
- lib/winds-up-client.rb
Instance Method Summary collapse
-
#initialize(attributes) ⇒ TerminalTable
constructor
A new instance of TerminalTable.
- #to_s ⇒ Object
Constructor Details
#initialize(attributes) ⇒ TerminalTable
10 11 12 |
# File 'lib/winds-up-client.rb', line 10 def initialize attributes @rows = attributes[:rows] end |
Instance Method Details
#to_s ⇒ Object
14 15 16 17 18 19 20 |
# 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 |