money_test 0.0.1 → 0.0.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 +4 -4
- data/lib/money_test.rb +7 -12
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c8ed964c8ee992a2d25c679986a694c84a6f7cc
|
4
|
+
data.tar.gz: 6c63d39cf28f5cb36b4edbe86acf2c7639de02b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 284707c303d5927420cd0d58a5e2b49793e111a2161c48ba22c3eeffd2f1032e70eeeb17f052ef178b9e2806a57d47b3fc5eca64243ad40d79283d95fd44440c
|
7
|
+
data.tar.gz: f652e40f1fe2103ca7d31bf3ad2774093ceb69d9c3568b675aed61b38ce9056c47916a5300a14370a16f21cac6a0b62bc95fcac67013a5d1c47e107dbc17ec17
|
data/lib/money_test.rb
CHANGED
@@ -16,15 +16,12 @@ class Money
|
|
16
16
|
@currency = currency
|
17
17
|
end
|
18
18
|
|
19
|
-
# Setting the different conversion rates with respect to
|
20
|
-
# the base currency
|
19
|
+
# Setting the different conversion rates with respect to the base currency
|
21
20
|
# == Parameters:
|
22
21
|
# base_currency::
|
23
|
-
# The base currency upon which the conversion rates should
|
24
|
-
# calculate, example: 'EUR', 'USD'
|
22
|
+
# The base currency upon which the conversion rates should calculate, example: 'EUR', 'USD'
|
25
23
|
# conversion_rates::
|
26
|
-
# A hash containing the different exchange rates' currencies
|
27
|
-
# and values with respect to the base currency, example:
|
24
|
+
# A hash containing the different exchange rates' currencies and values with respect to the base currency, example:
|
28
25
|
# {
|
29
26
|
# 'USD' => 1.11,
|
30
27
|
# 'Bitcoin' => 0.0047
|
@@ -34,8 +31,7 @@ class Money
|
|
34
31
|
@@conversion_rates = conversion_rates
|
35
32
|
end
|
36
33
|
|
37
|
-
# Converting the amount in the calling object upon the currency
|
38
|
-
# entered, with respect to the base currency
|
34
|
+
# Converting the amount in the calling object upon the currency entered, with respect to the base currency
|
39
35
|
# == Returns:
|
40
36
|
# A money object with the new amount and currency
|
41
37
|
def convert_to(to_currency)
|
@@ -47,7 +43,7 @@ class Money
|
|
47
43
|
Money.new(converted_amount, to_currency)
|
48
44
|
end
|
49
45
|
|
50
|
-
#
|
46
|
+
# Overriding arithmetic operators
|
51
47
|
def +(other)
|
52
48
|
rate = Money.getRate(other.currency, self.currency)
|
53
49
|
new_other_amount = other.amount * rate
|
@@ -69,7 +65,7 @@ class Money
|
|
69
65
|
end
|
70
66
|
# --------------------------------
|
71
67
|
|
72
|
-
#
|
68
|
+
# Overriding comparisons operators, to the nearest 2 decimal places
|
73
69
|
def ==(other)
|
74
70
|
temp = other.convert_to(self.currency)
|
75
71
|
return self.amount.round(2) == temp.amount.round(2)
|
@@ -97,8 +93,7 @@ class Money
|
|
97
93
|
# Getting the exchange rate between 2 currencies
|
98
94
|
# == Returns:
|
99
95
|
# - 1 if the 2 currencies are the same
|
100
|
-
# - the required rate, even if the 2 currencies are swaped
|
101
|
-
# (return inverse the value)
|
96
|
+
# - the required rate, even if the 2 currencies are swaped (return inverse the value)
|
102
97
|
# == Raises:
|
103
98
|
# - RateNotFound if no rates are set for those 2 currencies
|
104
99
|
def self.getRate(from_currency, to_currency)
|