euro_currency_conversion_rate 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/euro_currency_conversion_rate.rb +28 -3
- 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: 2b881c81453eeefc333cc062603be099bd578c03
|
4
|
+
data.tar.gz: 6b66aea9101682f554c7ada279f96bbd580452e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8defaf494d49e316d5a89f414059d62d87a35ce1014f43a6a7e95694aa4f035e839411e56ea9c0e9a2324ab02f58db84eea8714ac379a41eb94d09b65038ea4
|
7
|
+
data.tar.gz: 2836dbfb2dd97a334eac1f9cb3f20784aeed08cb245e86ba07c0b2529dd05e751a63fe701ea394e6ed605eb25d0cf21984308c1c60f5cda0e2affedbfcfc5d3e
|
@@ -1,17 +1,17 @@
|
|
1
1
|
require 'httparty'
|
2
2
|
|
3
3
|
class EuroCurrencyConversionRate
|
4
|
-
|
4
|
+
|
5
5
|
API_URL = 'http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'
|
6
6
|
|
7
7
|
class << self
|
8
8
|
|
9
|
-
#
|
9
|
+
# returns the latest exchange rate in float for a currency w.r.t. EUR
|
10
10
|
#
|
11
11
|
# Example:
|
12
12
|
# >> EuroCurrencyConversionRate.rate('USD')
|
13
13
|
# => 1.21
|
14
|
-
#
|
14
|
+
#
|
15
15
|
#
|
16
16
|
# Arguments:
|
17
17
|
# currency: (String)
|
@@ -21,6 +21,31 @@ class EuroCurrencyConversionRate
|
|
21
21
|
currency_exchange_rate['rate'].to_f unless currency_exchange_rate.nil?
|
22
22
|
end
|
23
23
|
|
24
|
+
# returns a hash containing the latest exchange rates for a list of currencies w.r.t EUR
|
25
|
+
#
|
26
|
+
#
|
27
|
+
# Example:
|
28
|
+
# >> EuroCurrencyConversionRate.rates([:usd, :chf, :inr])
|
29
|
+
# => {:usd=>1.0978, :chf=>1.0349, :inr=>69.7761}
|
30
|
+
# >> EuroCurrencyConversionRate.rates
|
31
|
+
# => {:usd=>1.0978, :jpy=>133.39, :bgn=>1.9558, :czk=>27.372, :dkk=>7.4552, :gbp=>0.71, :huf=>307.71, :pln=>4.1075, :ron=>4.4539, :sek=>9.2425, :chf=>1.0349, :nok=>8.39, :hrk=>7.5383, :rub=>54.881, :try=>2.8665, :aud=>1.4023, :brl=>3.425, :cad=>1.3496, :cny=>6.8098, :hkd=>8.51, :idr=>14471.4, :ils=>4.269, :inr=>69.7761, :krw=>1204.41, :mxn=>16.7662, :myr=>3.9668, :nzd=>1.5025, :php=>48.958, :sgd=>1.4728, :thb=>36.882, :zar=>13.1034}
|
32
|
+
#
|
33
|
+
#
|
34
|
+
# Arguments:
|
35
|
+
# currencies: (Array)
|
36
|
+
def rates(currencies = [])
|
37
|
+
currencies = currencies.map{ |c| c.to_s.upcase }
|
38
|
+
if currencies.empty?
|
39
|
+
result_arr = currency_exchange_array
|
40
|
+
else
|
41
|
+
result_arr = currency_exchange_array.select{ |ca| currencies.include?(ca['currency']) }
|
42
|
+
end
|
43
|
+
result_hash = {}
|
44
|
+
result_arr.map{ |ra| result_hash[ra['currency'].downcase.to_sym] = ra['rate'].to_f }
|
45
|
+
result_hash[:eur] = 1.0 if currencies.include?('EUR')
|
46
|
+
result_hash
|
47
|
+
end
|
48
|
+
|
24
49
|
private
|
25
50
|
|
26
51
|
def currency_exchange_array
|