Class: BankPayments::SwedbankImport::AmountConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/bank_payments/swedbank_import/amount_converter.rb

Overview

Used to convert Swedbanks numeric representation to a Ruby BigDecimal. It especially handles the convetion that that negative numbers have the last digits set as a char according to the DIGIT_MAP

Author:

  • Michael Litton

Constant Summary collapse

DIGIT_MAP =
{
  'å' => '0',
  'J' => '1',
  'K' => '2',
  'L' => '3',
  'M' => '4',
  'N' => '5',
  'O' => '6',
  'P' => '7',
  'Q' => '8',
  'R' => '9',
}.freeze

Class Method Summary collapse

Class Method Details

.value_to_decimal(value) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/bank_payments/swedbank_import/amount_converter.rb', line 26

def self.value_to_decimal(value)
  modifier = 1

  if value[-1] =~ /\D/
    modifier = -1
    value = value[0..-2] + DIGIT_MAP[value[-1]]
  end

  BigDecimal("#{value[0..-3]}.#{value[-2..-1]}") * modifier
end