Module: Sequel::PrettyTable

Defined in:
lib/sequel/extensions/pretty_table.rb

Class Method Summary collapse

Class Method Details

Prints nice-looking plain-text tables via puts

+--+-------+
|id|name   |
|--+-------|
|1 |fasdfas|
|2 |test   |
+--+-------+


22
23
24
25
26
27
28
29
30
31
32
# File 'lib/sequel/extensions/pretty_table.rb', line 22

def self.print(records, columns = nil) # records is an array of hashes
  columns ||= records.first.keys.sort_by{|x|x.to_s}
  sizes = column_sizes(records, columns)
  sep_line = separator_line(columns, sizes)

  puts sep_line
  puts header_line(columns, sizes)
  puts sep_line
  records.each {|r| puts data_line(columns, sizes, r)}
  puts sep_line
end