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.
36 37 38 39 40 41 |
# File 'lib/mgit/output.rb', line 36 def initialize(table, ) @table = table = [:columns] = [] fail ImplementationError, 'ptable called with invalid table' unless valid_table? end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
34 35 36 |
# File 'lib/mgit/output.rb', line 34 def end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
34 35 36 |
# File 'lib/mgit/output.rb', line 34 def table @table end |
Instance Method Details
#to_s ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/mgit/output.rb', line 43 def to_s return '' if table.empty? cw = column_widths 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 |