Class: MGit::Output::TableOutputter
- Inherits:
-
Object
- Object
- MGit::Output::TableOutputter
- Defined in:
- lib/mgit/output.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Instance Method Summary collapse
-
#initialize(table, options) ⇒ TableOutputter
constructor
A new instance of TableOutputter.
- #to_s ⇒ Object
Constructor Details
#initialize(table, options) ⇒ TableOutputter
Returns a new instance of TableOutputter.
24 25 26 27 28 |
# File 'lib/mgit/output.rb', line 24 def initialize(table, ) @table = table @options = raise ImplementationError.new('ptable called with invalid table') unless valid_table? end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
22 23 24 |
# File 'lib/mgit/output.rb', line 22 def @options end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
22 23 24 |
# File 'lib/mgit/output.rb', line 22 def table @table end |
Instance Method Details
#to_s ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/mgit/output.rb', line 30 def to_s cw = column_widths if [:columns] [:columns].each_with_index do |c, i| cw[i] = c if c end end table.map do |row| row.map.with_index do |cell, i| # Only justify the column if it is not the last one. # This avoids too many line breaks. i < (columns - 1) ? justify(cell, cw[i]) : cell end.join(' | ') end.join("\n") end |