class ET::Formatter
Constants
- BLACK
- BLUE
- BOLD
- CLEAR
- CYAN
- GREEN
- MAGENTA
- RED
- WHITE
- YELLOW
Public Class Methods
print_table(data, *headers)
click to toggle source
# File lib/et/formatter.rb, line 3 def self.print_table(data, *headers) return puts "No challenges assigned" if data.empty? column_widths = headers.map do |header| data.map { |row| row[header].length }.max end total_width = column_widths.reduce(0) do |width, sum| sum + width + 3 end header = build_row(headers, column_widths, YELLOW) puts header puts "\e[34m" + ("-" * total_width) + "\e[0m" data.each do |row| values = headers.map { |header| row[header] } puts build_row(values, column_widths, WHITE) end end
Private Class Methods
build_row(row, widths, color)
click to toggle source
# File lib/et/formatter.rb, line 26 def self.build_row(row, widths, color) row.zip(widths).map do |value, width| " \e[#{color}m%-#{width}s\e[0m " % value end.join("\e[34m|\e[0m") end