Class: MGit::Output::TableOutputter

Inherits:
Object
  • Object
show all
Defined in:
lib/mgit/output.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options)
  @table = table
  @options = options
  @options[:columns] = []
  fail ImplementationError, 'ptable called with invalid table' unless valid_table?
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



34
35
36
# File 'lib/mgit/output.rb', line 34

def options
  @options
end

#tableObject (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_sObject



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