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 |
+--+-------+
24 25 26 |
# File 'lib/sequel/extensions/_pretty_table.rb', line 24 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.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/sequel/extensions/_pretty_table.rb', line 29 def self.string(records, columns = nil) # records is an array of hashes columns ||= records.first.keys.sort 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 |