Class: Ey::Core::Cli::Helpers::StreamPrinter::Printer

Inherits:
Object
  • Object
show all
Defined in:
lib/ey-core/cli/helpers/stream_printer.rb

Instance Method Summary collapse

Constructor Details

#initialize(rows = {}) ⇒ Printer

Returns a new instance of Printer.



12
13
14
# File 'lib/ey-core/cli/helpers/stream_printer.rb', line 12

def initialize(rows = {})
  @rows = rows
end

Instance Method Details

#format(value, width) ⇒ Object



33
34
35
# File 'lib/ey-core/cli/helpers/stream_printer.rb', line 33

def format(value, width)
  TablePrint::FixedWidthFormatter.new(width).format(value)
end


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ey-core/cli/helpers/stream_printer.rb', line 15

def print(*vals)
  unless @header_printed
    header = []
    separator = []
    @rows.each do |k,v|
      header << format(k, v)
      separator << '-' * v
    end
    puts header.join("| ")
    puts separator.join("|-")
    @header_printed = true
  end
  line = []
  vals.each_with_index do |v,index|
    line << format(v, @rows.values[index])
  end
  puts line.join("| ")
end