Class: LedgerWeb::Decorators::NumberDecorator

Inherits:
Object
  • Object
show all
Defined in:
lib/ledger_web/decorators.rb

Instance Method Summary collapse

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