Class: IV::CLI::Formatter::Table

Inherits:
Base
  • Object
show all
Defined in:
lib/iv-cli/formatters/table.rb

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from Base

find, #initialize

Methods included from Helpers::SubclassRegistration

included

Methods included from Helpers::Errors

included

Constructor Details

This class inherits a constructor from IV::CLI::Formatter::Base

Instance Method Details

#output_rows(list) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/iv-cli/formatters/table.rb', line 7

def output_rows(list)
  column_width = {}

  # find column width by searching out widest member of each column
  options[:columns].each do |column|
    column_width[column] = largest_size(list, column)
  end

  # print row of headers every so often
  headers = []
  options[:columns].each do |key|
    headers << sprintf(" %#{column_width[key]}s ", key.to_s)
  end
  print_row(headers, "+")

  # print out each row
  list.each do |member|
    output = []
    options[:columns].each do |key|
      output << sprintf(" %-#{column_width[key]}s ", remove_color(member[key]))
    end
    print_row(output)
  end
  STDOUT.flush
end