Class: LedgerWeb::Decorators::NumberDecorator
- Inherits:
-
Object
- Object
- LedgerWeb::Decorators::NumberDecorator
- Defined in:
- lib/ledger_web/decorators.rb
Instance Method Summary collapse
- #decorate(cell, row) ⇒ Object
-
#initialize(precision = 2) ⇒ NumberDecorator
constructor
A new instance of NumberDecorator.
Constructor Details
#initialize(precision = 2) ⇒ NumberDecorator
Returns a new instance of NumberDecorator.
5 6 7 |
# File 'lib/ledger_web/decorators.rb', line 5 def initialize(precision=2) @precision = precision end |
Instance Method Details
#decorate(cell, row) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/ledger_web/decorators.rb', line 9 def decorate(cell, row) if cell.value.is_a?(Numeric) cell.align = 'right' cell.text = sprintf("%0.#{@precision}f", cell.value) end cell end |