Class: Freyia::Shell::ColumnPrinter
- Inherits:
-
Object
- Object
- Freyia::Shell::ColumnPrinter
- Defined in:
- lib/freyia/shell/column_printer.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Instance Method Summary collapse
-
#initialize(stdout, **options) ⇒ ColumnPrinter
constructor
A new instance of ColumnPrinter.
-
#print(array) ⇒ Object
rubocop:todo Metrics.
Constructor Details
#initialize(stdout, **options) ⇒ ColumnPrinter
Returns a new instance of ColumnPrinter.
10 11 12 13 14 |
# File 'lib/freyia/shell/column_printer.rb', line 10 def initialize(stdout, **) @stdout = stdout @options = @indent = [:indent].to_i end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/freyia/shell/column_printer.rb', line 8 def @options end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
8 9 10 |
# File 'lib/freyia/shell/column_printer.rb', line 8 def stdout @stdout end |
Instance Method Details
#print(array) ⇒ Object
rubocop:todo Metrics
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/freyia/shell/column_printer.rb', line 16 def print(array) # rubocop:todo Metrics 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 |