Module: SchwarmCli::Formatters::Table
- Defined in:
- lib/schwarm_cli/formatters/table.rb
Class Method Summary collapse
Class Method Details
.format_list(records, columns:) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/schwarm_cli/formatters/table.rb', line 6 def self.format_list(records, columns:) if records.empty? puts "No results found." return end widths = column_widths(records, columns) puts format_row(columns.map(&:first), columns, widths) records.each do |record| puts format_row(columns.map { |_, key| record[key].to_s }, columns, widths) end end |
.format_record(record, fields:) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/schwarm_cli/formatters/table.rb', line 19 def self.format_record(record, fields:) label_width = fields.keys.map(&:length).max fields.each do |label, key| puts "#{label.rjust(label_width)}: #{record[key]}" end end |