Class: Thor::Shell::TablePrinter
- Inherits:
-
ColumnPrinter
- Object
- ColumnPrinter
- Thor::Shell::TablePrinter
- Defined in:
- lib/thor/shell/table_printer.rb
Constant Summary collapse
- BORDER_SEPARATOR =
:separator
Instance Attribute Summary
Attributes inherited from ColumnPrinter
Instance Method Summary collapse
-
#initialize(stdout, options = {}) ⇒ TablePrinter
constructor
A new instance of TablePrinter.
- #print(array) ⇒ Object
Constructor Details
#initialize(stdout, options = {}) ⇒ TablePrinter
Returns a new instance of TablePrinter.
9 10 11 12 13 14 15 16 |
# File 'lib/thor/shell/table_printer.rb', line 9 def initialize(stdout, = {}) super @formats = [] @maximas = [] @colwidth = [:colwidth] @truncate = [:truncate] == true ? Terminal.terminal_width : [:truncate] @padding = 1 end |
Instance Method Details
#print(array) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/thor/shell/table_printer.rb', line 18 def print(array) return if array.empty? prepare(array) print_border_separator if [:borders] array.each do |row| if [:borders] && row == BORDER_SEPARATOR print_border_separator next end sentence = "".dup row.each_with_index do |column, index| sentence << format_cell(column, row.size, index) end sentence = truncate(sentence) sentence << "|" if [:borders] stdout.puts indentation + sentence end print_border_separator if [:borders] end |