foreign_currency_exchange 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11fd1b7993283a906151242c99dca97902585b18
|
4
|
+
data.tar.gz: 6ba6f7884446f3490237d6a4a7298270a8aadcbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1c239dc8fd0bee0ec3d95774ef79096b2add4b6139cab693fa2a67728f6af7264cd07a2a31227737deb0e916c56971c3651d0e8159f4fc876033f29eeac3d96
|
7
|
+
data.tar.gz: a99b889d14a81e49c13a16da7f84b81ba59d24c3b16a2120bd2b3077e83eb60938d0c4cc97371324643e2829be72dcf1a1618393e334aea1f7f6a9bd175fa249
|
@@ -17,7 +17,7 @@ module ForeignCurrencyExchange
|
|
17
17
|
def initialize(amount, currency)
|
18
18
|
check_configuration # Configuration should be valid.
|
19
19
|
check_currency(currency) # Currency should be configured before.
|
20
|
-
@amount =
|
20
|
+
@amount = prepare_amount(amount)
|
21
21
|
@currency = currency
|
22
22
|
end
|
23
23
|
|
@@ -25,7 +25,7 @@ module ForeignCurrencyExchange
|
|
25
25
|
# or converted current object amount to base_currency otherwise.
|
26
26
|
def base_amount
|
27
27
|
return amount if currency == base_currency
|
28
|
-
(amount / rates[currency].to_f)
|
28
|
+
prepare_amount(amount / rates[currency].to_f)
|
29
29
|
end
|
30
30
|
|
31
31
|
def <=>(other)
|
@@ -72,8 +72,12 @@ module ForeignCurrencyExchange
|
|
72
72
|
|
73
73
|
private
|
74
74
|
|
75
|
+
def prepare_amount(amount)
|
76
|
+
amount.integer? ? amount : amount.round(ROUND_LEVEL)
|
77
|
+
end
|
78
|
+
|
75
79
|
def formatted_amount
|
76
|
-
amount.
|
80
|
+
amount.integer? ? amount.to_s : format(AMOUNT_FORMAT, amount)
|
77
81
|
end
|
78
82
|
|
79
83
|
# Returns amount based on given currency,
|