Class: SepaFileParser::Misc

Inherits:
Object
  • Object
show all
Defined in:
lib/sepa_file_parser/misc.rb

Class Method Summary collapse

Class Method Details

.to_amount(value) ⇒ BigDecimal?

Parameters:

Returns:

  • (BigDecimal, nil)


20
21
22
23
24
# File 'lib/sepa_file_parser/misc.rb', line 20

def to_amount(value)
  return nil if value == nil || value.strip == ''

  BigDecimal(value.tr(',', '.'))
end

.to_amount_in_cents(value) ⇒ Integer?

Parameters:

Returns:

  • (Integer, nil)


9
10
11
12
13
14
15
16
# File 'lib/sepa_file_parser/misc.rb', line 9

def to_amount_in_cents(value)
  return nil if value == nil || value.strip == ''

  # Using dollars and cents as representation for parts before and after the decimal separator
  dollars, cents = value.split(/,|\./)
  cents ||= '0'
  format('%s%s', dollars, cents.ljust(2, '0')).to_i
end