Class: Razor::CLI::TableFormat
- Inherits:
-
Object
- Object
- Razor::CLI::TableFormat
- Includes:
- CommandLineReporter
- Defined in:
- lib/razor/cli/table_format.rb
Instance Method Summary collapse
Instance Method Details
#get_headers(doc) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/razor/cli/table_format.rb', line 32 def get_headers(doc) [].tap do |headers| doc.map do |page| page.map do |item| headers << item[0] unless headers.include?(item[0]) end end end end |
#get_width(header, doc) ⇒ Object
26 27 28 29 30 |
# File 'lib/razor/cli/table_format.rb', line 26 def get_width(header, doc) (doc.map do |page| (page[header] or '').to_s.length end << header.to_s.length).max end |
#run(doc, column_overrides) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/razor/cli/table_format.rb', line 5 def run(doc, column_overrides) suppress_output table(:border => true, :encoding => :ascii) do headings = (column_overrides or get_headers(doc)) row do headings.each do |header| column(header, :width => get_width(header, doc)) end end doc.each do |page| row do headings.each do |heading| column(page[heading]) end end end end # Capturing stores the string, rather than printing to STDOUT (default). capture_output.strip end |