class Rapport::CellFormatter
Public Class Methods
new(procs = {})
click to toggle source
# File lib/rapport/report_generator.rb, line 75 def initialize(procs = {}) @procs = procs end
Public Instance Methods
add_cell_format(type, &block)
click to toggle source
# File lib/rapport/report_generator.rb, line 83 def add_cell_format(type, &block) proc = Proc.new(&block) @procs[type] = proc @procs[Rapport.format_underscore(type.to_s)] = proc if type.is_a?(Class) # Support ActiveSupport::TimeWithZone automatically if type == Time add_cell_format(ActiveSupport::TimeWithZone, &block) rescue nil end end
dup()
click to toggle source
# File lib/rapport/report_generator.rb, line 79 def dup CellFormatter.new(@procs.dup) end
format(type,value)
click to toggle source
# File lib/rapport/report_generator.rb, line 95 def format(type,value) if type.is_a?(Proc) type.call(value) else proc = @procs[type] || @procs[value.class] proc.nil? ? value : proc.call(value) end end