class CamtParser::Misc

Public Class Methods

to_amount(value) click to toggle source

@param value [nil, String] @return [BigDecimal, nil]

# File lib/camt_parser/misc.rb, line 18
def to_amount(value)
  return nil if value == nil || value.strip == ''

  BigDecimal(value.tr(',', '.'))
end
to_amount_in_cents(value) click to toggle source

@param value [nil, String] @return [Integer, nil]

# File lib/camt_parser/misc.rb, line 7
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