Class: IV::CLI::Formatter::Table
- Defined in:
- lib/iv-cli/formatters/table.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
Methods included from Helpers::SubclassRegistration
Methods included from Helpers::Errors
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 [:columns].each do |column| column_width[column] = largest_size(list, column) end # print row of headers every so often headers = [] [: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 = [] [:columns].each do |key| output << sprintf(" %-#{column_width[key]}s ", remove_color(member[key])) end print_row(output) end STDOUT.flush end |