Module: Sequel::PrettyTable
- Defined in:
- lib/sequel/extensions/_pretty_table.rb
Class Method Summary collapse
-
.print(records, columns = nil) ⇒ Object
Prints nice-looking plain-text tables via puts.
-
.string(records, columns = nil) ⇒ Object
Return the string that #print will print via puts.
Class Method Details
.print(records, columns = nil) ⇒ Object
Prints nice-looking plain-text tables via puts
+--+-------+
|id|name |
|--+-------|
|1 |fasdfas|
|2 |test |
+--+-------+
20 21 22 |
# File 'lib/sequel/extensions/_pretty_table.rb', line 20 def self.print(records, columns=nil) puts string(records, columns) end |
.string(records, columns = nil) ⇒ Object
Return the string that #print will print via puts.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/sequel/extensions/_pretty_table.rb', line 25 def self.string(records, columns = nil) # records is an array of hashes columns ||= records.first.keys.sort_by(&:to_s) sizes = column_sizes(records, columns) sep_line = separator_line(columns, sizes) array = [sep_line, header_line(columns, sizes), sep_line] records.each {|r| array << data_line(columns, sizes, r)} array << sep_line array.join("\n") end |