rk_fx_rates 0.0.2 → 0.1.0
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/exchange_rates.store +2177 -2176
- data/lib/rk_fx_rates/provider/ecb.rb +4 -3
- data/lib/rk_fx_rates/version.rb +1 -1
- data/lib/rk_fx_rates.rb +11 -4
- data/spec/lib/rk_fx_rates_spec.rb +9 -0
- metadata +1 -1
@@ -9,13 +9,14 @@ module RkFxRates
|
|
9
9
|
# see rk_fx_rates.rb for data structure description
|
10
10
|
def self.generate_fx_hash(data)
|
11
11
|
fx_hash = Hash.new
|
12
|
+
fx_hash["data"] = Hash.new
|
12
13
|
fx_hash["downloaded_at"] = Date.today
|
13
|
-
|
14
|
+
|
14
15
|
data["Envelope"]["Cube"]["Cube"].each do |daily|
|
15
16
|
date = Chronic.parse( daily["time"] ).to_date
|
16
|
-
fx_hash[date] = Hash.new
|
17
|
+
fx_hash["data"][date] = Hash.new
|
17
18
|
daily["Cube"].each do |currency|
|
18
|
-
fx_hash[date] [currency["currency"]] = currency["rate"].to_f
|
19
|
+
fx_hash["data"][date] [currency["currency"]] = currency["rate"].to_f
|
19
20
|
end
|
20
21
|
end
|
21
22
|
return fx_hash
|
data/lib/rk_fx_rates/version.rb
CHANGED
data/lib/rk_fx_rates.rb
CHANGED
@@ -25,6 +25,7 @@ module RkFxRates
|
|
25
25
|
|
26
26
|
def initialize(source = RkFxRates::Provider::Ecb)
|
27
27
|
@source = source
|
28
|
+
@fx_hash = retrieve
|
28
29
|
end
|
29
30
|
|
30
31
|
def retrieve
|
@@ -49,18 +50,24 @@ module RkFxRates
|
|
49
50
|
return to_euro(date, from_currency) * from_euro(date, to_currency)
|
50
51
|
end
|
51
52
|
|
53
|
+
def available_currencies
|
54
|
+
@fx_hash["data"].first[1].keys
|
55
|
+
end
|
56
|
+
|
57
|
+
def available_dates
|
58
|
+
return @fx_hash["data"].keys
|
59
|
+
end
|
60
|
+
|
52
61
|
private
|
53
62
|
|
54
63
|
def from_euro(date, to_currency)
|
55
64
|
return 1.0 if to_currency == 'EUR'
|
56
|
-
|
57
|
-
rate = data[date][to_currency]
|
65
|
+
rate = @fx_hash["data"][date][to_currency]
|
58
66
|
end
|
59
67
|
|
60
68
|
def to_euro(date, from_currency)
|
61
69
|
return 1.0 if from_currency == 'EUR'
|
62
|
-
|
63
|
-
rate = 1.0 / data[date][from_currency]
|
70
|
+
rate = 1.0 / @fx_hash["data"][date][from_currency]
|
64
71
|
end
|
65
72
|
|
66
73
|
def store(fx_hash)
|
@@ -31,6 +31,15 @@ describe RkFxRates do
|
|
31
31
|
@fx_api.at(date, 'EUR', 'EUR').should be == 1.0
|
32
32
|
end
|
33
33
|
|
34
|
+
it "should provide a list with the available currencies" do
|
35
|
+
@fx_api.available_currencies.should include("USD")
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should provide a list with the available dates" do
|
39
|
+
date = Chronic.parse('last monday').to_date
|
40
|
+
@fx_api.available_dates.should include(date)
|
41
|
+
end
|
42
|
+
|
34
43
|
context "with existing and current data" do
|
35
44
|
before(:each) do
|
36
45
|
@fx_api.retrieve_latest
|