Class: Bundler::Thor::Shell::ColumnPrinter

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb

Direct Known Subclasses

TablePrinter, WrappedPrinter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stdout, options = {}) ⇒ ColumnPrinter

Returns a new instance of ColumnPrinter.



8
9
10
11
12
# File 'lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb', line 8

def initialize(stdout, options = {})
  @stdout = stdout
  @options = options
  @indent = options[:indent].to_i
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb', line 6

def options
  @options
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



6
7
8
# File 'lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb', line 6

def stdout
  @stdout
end

Instance Method Details



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb', line 14

def print(array)
  return if array.empty?
  colwidth = (array.map { |el| el.to_s.size }.max || 0) + 2
  array.each_with_index do |value, index|
    # Don't output trailing spaces when printing the last column
    if ((((index + 1) % (Terminal.terminal_width / colwidth))).zero? && !index.zero?) || index + 1 == array.length
      stdout.puts value
    else
      stdout.printf("%-#{colwidth}s", value)
    end
  end
end