Module: DbAgile::IO::PrettyTable

Defined in:
lib/dbagile/io/pretty_table.rb

Overview

Helper to create pretty tables (very much inspired from Sequel’s PrettyTable, see file licence header for details).

Class Method Summary collapse

Class Method Details

Prints nice-looking plain-text tables



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/dbagile/io/pretty_table.rb', line 35

def self.print(records, columns, buffer = "", options = {}) # records is an array of hashes
  # investigate arguments
  sizes = column_sizes(records, columns)
  sep_line = normalize_line(separator_line(columns, sizes), options)

  # start generation now
  buffer << sep_line << "\n"
  buffer << normalize_line(header_line(columns, sizes),options) << "\n"
  buffer << sep_line << "\n"
  records.each {|r| 
    buffer << normalize_line(data_line(columns, sizes, r),options) << "\n"
  }
  buffer << sep_line << "\n"
  buffer
end