class ChefCLI::Policyfile::Reports::TablePrinter
for each cell.
method, individual rows are printed by calling #print_row with the data
the table. Columns are defined ahead of time, by calling the #column
Defines a table with a flexible number of columns and prints rows in
def column(collection = [])
of strings and the longest string is used as the left justify width
Defines a column. If a collection is given, it is mapped to an array
def column(collection = []) @column_widths << (collection.map(&:to_s).map(&:size).max || 0) end
def initialize(ui)
def initialize(ui) @ui = ui @column_widths = [] yield self end
def print_row(*cells)
def print_row(*cells) row = "" cells.each_with_index do |cell_data, i| row << cell_data.to_s.ljust(@column_widths[i]) row << " " end ui.msg(row.strip) end