3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/virtuaaliviivakoodi/amount_normalizer.rb', line 3
def self.call(value)
amount = value.to_f
if amount
raise(ArgumentError, "Amount is negative") if (amount < 0)
raise(ArgumentError, "Amount is too large, maximum is 999999.99") if (amount > 999999.99)
decimals = digits_after_decimal_point(amount)
raise(ArgumentError, "There can't be more than two decimals") if decimals > 2
euros, cents = sprintf("%0.02f", amount).split(".")
Virtuaaliviivakoodi.pad(euros, 6) + cents
else
Virtuaaliviivakoodi.pad("", 8)
end
end
|