rk_fx_rates 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -1,3 +1,3 @@
1
1
  module RkFxRates
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
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
- data = retrieve
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
- data = retrieve
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rk_fx_rates
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rainer Kuhn