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
-
.print(records, columns, buffer = "", options = {}) ⇒ Object
Prints nice-looking plain-text tables.
Class Method Details
.print(records, columns, buffer = "", options = {}) ⇒ Object
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 = "", = {}) # records is an array of hashes # investigate arguments sizes = column_sizes(records, columns) sep_line = normalize_line(separator_line(columns, sizes), ) # start generation now buffer << sep_line << "\n" buffer << normalize_line(header_line(columns, sizes),) << "\n" buffer << sep_line << "\n" records.each {|r| buffer << normalize_line(data_line(columns, sizes, r),) << "\n" } buffer << sep_line << "\n" buffer end |