Class: CFONB::OperationDetail::MMO

Inherits:
Object
  • Object
show all
Defined in:
lib/cfonb/operation_detail/mmo.rb

Constant Summary collapse

ATTRIBUTES =
%i[original_currency original_amount exchange_rate].freeze

Class Method Summary collapse

Class Method Details

.apply(operation, line) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/cfonb/operation_detail/mmo.rb', line 10

def self.apply(operation, line)
  operation.original_currency = line.detail[0..2]

  scale = line.detail[3].to_i
  sign = operation.amount <=> 0 # the detail amount is unsigned

  operation.original_amount = sign * BigDecimal(line.detail[4..17]) / (10**scale)
  exchange_rate_value = line.detail[26..29]

  return if exchange_rate_value.nil? || exchange_rate_value.strip.empty?

  exchange_rate_scale = line.detail[18]
  operation.exchange_rate = BigDecimal(exchange_rate_value) / (10**BigDecimal(exchange_rate_scale))
end