omni_exchange 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -8
- data/Gemfile.lock +2 -2
- data/README.md +7 -2
- data/lib/omni_exchange/version.rb +1 -1
- data/lib/omni_exchange.rb +3 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf795bf43c3ede8973124f10ff3afa6190a4c6af4705ecc481bf2a1112477f33
|
4
|
+
data.tar.gz: 4b8fc48b43b3cbcb9e118d8e1ee5238c71c9ddfceca7aa1cf1034a78fa693691
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a42a179b5435a78d4aacd65c04e4c26223c1115c53b3160963ace5c8175dce8252a1ae7fc2272e758d16c0264c99294ac3a84763f0fa1f4cf5a51d08746327c3
|
7
|
+
data.tar.gz: 58186c5c5697ef71566e41ad717b4c76362e2650edc1bd72da11ff0964bc76e7e5936f656969b58e37f69f6f34e640c1f09cba2041eeeb25a73ad27fae037ef3
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
omni_exchange (1.
|
4
|
+
omni_exchange (1.6.0)
|
5
5
|
faraday (< 2)
|
6
6
|
money (~> 6.13.1)
|
7
7
|
|
@@ -13,7 +13,7 @@ GEM
|
|
13
13
|
concurrent-ruby (1.1.10)
|
14
14
|
diff-lcs (1.5.0)
|
15
15
|
dotenv (2.8.1)
|
16
|
-
faraday (1.10.
|
16
|
+
faraday (1.10.2)
|
17
17
|
faraday-em_http (~> 1.0)
|
18
18
|
faraday-em_synchrony (~> 1.0)
|
19
19
|
faraday-excon (~> 1.1)
|
data/README.md
CHANGED
@@ -57,7 +57,8 @@ To convert currency and/or get an exchange rate, all you have to do is call `Omn
|
|
57
57
|
What you get back is a hash containing:
|
58
58
|
1. converted_amount: (BigDecimal) the amount of money exchanged from the base currency to the target currency
|
59
59
|
2. exchange_rate: (BigDecimal) the rate used to calculate the converted_amount
|
60
|
-
3.
|
60
|
+
3. non_subunit_fx_rate: (BigDecimal) an exchange rate that can be used to convert a formatted version of the base currency (ie. 100 USD being formatted as 1.00)
|
61
|
+
4. provider: (Symbol) the provider that supplied the exchange_rate (ie. :open_exchange_rates, :xe)
|
61
62
|
|
62
63
|
[For the sake of precise calculation](https://www.bigbinary.com/blog/handling-money-in-ruby), converted_amount and exchange_rate are BigDecimal. Simply call `.to_f` to the results if you'd like to see a number that is easier to read.
|
63
64
|
|
@@ -67,7 +68,7 @@ Here is an example. Lets say I want to convert $1.00 US Dollar to Japanese Yen,
|
|
67
68
|
```ruby
|
68
69
|
USD_to_JPY = OmniExchange.get_fx_data(amount: 100, base_currency: 'USD', target_currency: 'JPY', providers: [:open_exchange_rates, :xe])
|
69
70
|
|
70
|
-
puts USD_to_JPY # => { :converted_amount=>0.13566633333e3, :exchange_rate=>0.13566633333e1, :provider=>:open_exchange_rates }
|
71
|
+
puts USD_to_JPY # => { :converted_amount=>0.13566633333e3, :exchange_rate=>0.13566633333e1, :non_subunit_fx_rate=>0.13566633333e3, :provider=>:open_exchange_rates }
|
71
72
|
|
72
73
|
puts USD_to_JPY[:converted_amount] # => 0.13566633333e3
|
73
74
|
puts USD_to_JPY[:converted_amount].to_f # => 135.66633333
|
@@ -75,6 +76,10 @@ puts USD_to_JPY[:converted_amount].to_f # => 135.66633333
|
|
75
76
|
puts USD_to_JPY[:exchange_rate] # => 0.13566633333e1
|
76
77
|
puts USD_to_JPY[:exchange_rate].to_f # => 1.3566633333
|
77
78
|
|
79
|
+
# :fx_rate can be used when 100 USD is written as 1.00 instead of 100. In other words, you can do 1.00 * USD_to_JPY[:non_subunit_fx_rate] and get 135.66633333
|
80
|
+
puts USD_to_JPY[:non_subunit_fx_rate] # => 0.13566633333e3
|
81
|
+
puts USD_to_JPY[:non_subunit_fx_rate].to_f # => 135.66633333
|
82
|
+
|
78
83
|
```
|
79
84
|
|
80
85
|
## Development
|
data/lib/omni_exchange.rb
CHANGED
@@ -53,6 +53,7 @@ module OmniExchange
|
|
53
53
|
# * :converted_amount [BigDecimal] the amount of money exchanged from the base currency to the target
|
54
54
|
# currency as a BigDecimal for precice calculation. ie. 1, 10, 100
|
55
55
|
# * :exchange_rate [BigDecimal] the rate used to calculate the converted_amount as a BigDecimal. ie. 0.95211e1
|
56
|
+
# * :non_subunit_fx_rate [BigDecimal] a rate that can be used when a currency with subunits is not in cents . ie. 0.95211e3
|
56
57
|
# * :provider [Symbol] the provider that supplied the exchange_rate data. ie. :xe, :open_exchange_rates
|
57
58
|
def get_fx_data(amount:, base_currency:, target_currency:, providers:)
|
58
59
|
# if one of the currencies is not valid (ie. 'fake_crypto'), an exception is raised.
|
@@ -71,10 +72,11 @@ module OmniExchange
|
|
71
72
|
# Gracefully hit each provider and fail-over to the next one
|
72
73
|
provider_classes.each do |klass|
|
73
74
|
rate = klass.get_exchange_rate(base_currency: base_currency, target_currency: target_currency)
|
75
|
+
plain_format_rate = (rate * Money::Currency.wrap(base_currency).subunit_to_unit).to_d
|
74
76
|
|
75
77
|
exchanged_amount = rate.to_d * amount.to_d
|
76
78
|
|
77
|
-
return { converted_amount: exchanged_amount, exchange_rate: rate, provider: OmniExchange::Provider.all.key(klass) }
|
79
|
+
return { converted_amount: exchanged_amount, exchange_rate: rate, non_subunit_fx_rate: plain_format_rate, provider: OmniExchange::Provider.all.key(klass) }
|
78
80
|
rescue *EXCEPTIONS, OmniExchange::XeMonthlyLimit, JSON::ParserError => e
|
79
81
|
error_messages << e.inspect
|
80
82
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omni_exchange
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yun Chung
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|