Class: Rapport::CellFormatter
- Inherits:
-
Object
- Object
- Rapport::CellFormatter
- Defined in:
- lib/rapport/report_generator.rb
Instance Method Summary collapse
- #add_cell_format(type, &block) ⇒ Object
- #dup ⇒ Object
- #format(type, value) ⇒ Object
-
#initialize(procs = {}) ⇒ CellFormatter
constructor
A new instance of CellFormatter.
Constructor Details
#initialize(procs = {}) ⇒ CellFormatter
Returns a new instance of CellFormatter.
75 76 77 |
# File 'lib/rapport/report_generator.rb', line 75 def initialize(procs = {}) @procs = procs end |
Instance Method Details
#add_cell_format(type, &block) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 |
# 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 ⇒ Object
79 80 81 |
# File 'lib/rapport/report_generator.rb', line 79 def dup CellFormatter.new(@procs.dup) end |
#format(type, value) ⇒ Object
95 96 97 98 99 100 101 102 |
# 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 |