class Goal::Report
Attributes
column_width[R]
data[R]
Public Class Methods
new(data, options = {})
click to toggle source
# File lib/goal/report.rb, line 3 def initialize(data, options = {}) @data = data @column_width = options.fetch(:column_width, 8) end
Public Instance Methods
to_s()
click to toggle source
# File lib/goal/report.rb, line 8 def to_s output = row(header) + "\n" data[:rows].each do |r| output += row([r[:goal], r[:expected], r[:average]]) + "\n" end output += footer output end
Private Instance Methods
header()
click to toggle source
# File lib/goal/report.rb, line 24 def header %w(Goals Expected Average) end
number_to_currency(value)
click to toggle source
# File lib/goal/report.rb, line 54 def number_to_currency(value) val_str = ("%.2f" % [value.to_s]).gsub('.', ',') while val_str.sub!(/(\d+)(\d\d\d)/, '\1.\2'); end val_str end
prepare_columns(columns)
click to toggle source
# File lib/goal/report.rb, line 48 def prepare_columns(columns) columns.map do |c| c.to_s.ljust(column_width) end end
row(columns)
click to toggle source
# File lib/goal/report.rb, line 42 def row(columns) prepared_columns = prepare_columns(columns) "| #{prepared_columns.join(' | ')} |" end