rk_fx_rates 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a28cba1b8c8892ef3a80a2c47d77400db00a5763
4
- data.tar.gz: 64d674a910a34d4e52e0f68a225ed47b4b7f0187
3
+ metadata.gz: 225f06ee6d4cc91ec236835358e7045a474fa735
4
+ data.tar.gz: d0808a1d0c945e5bcc8cd57f910465be741ee812
5
5
  SHA512:
6
- metadata.gz: 058483c08426b1cf35715950b3ecb6681badc5ee7d7eb822e70f168b005f50b61ed1ddcf096f79b0b154eb79f9280e669d94a4f9b7ec61903623297e211a92a2
7
- data.tar.gz: cc150c931632cc9938b72ca6b432faba37023de6625008424924bc552cffc361500046bbed3a05cc305ede2350d15f667394a0f93bce38e489aced7102fe456b
6
+ metadata.gz: bdb068e5b17f183941b755930f1c95c8f9a9d62b3afb57fb98eddbaad4788585bca9cd632443a67b52eb9f7e424da2a3cb58a8ffb81c3f434c24f8e8c991e321
7
+ data.tar.gz: 5a714ffb902a523ccc9dd301fc37c883ae1fefbc373b3760e7e2d6522ba5e80d618dcab508c6b5bb2618c0caf7988beab0dd271c647cfb3e37c24f3ac0eb4ae1
data/lib/rk_fx_rates.rb CHANGED
@@ -23,11 +23,14 @@ module RkFxRates
23
23
  class ExchangeRate
24
24
  include HTTParty
25
25
 
26
+
27
+ # Load Ecb as default provider
26
28
  def initialize(source = RkFxRates::Provider::Ecb)
27
29
  @source = source
28
30
  @fx_hash = retrieve
29
31
  end
30
32
 
33
+ # Only download the latest update when the stored data is outdated or not available
31
34
  def retrieve
32
35
  retrieve_latest unless File.exists?('exchange_rates.store')
33
36
  fx_hash = YAML::load_file('exchange_rates.store')['rates']
@@ -46,6 +49,7 @@ module RkFxRates
46
49
  return fx_hash
47
50
  end
48
51
 
52
+ # calculates the rate by converting to EUR first
49
53
  def at(date, from_currency, to_currency)
50
54
  return to_euro(date, from_currency) * from_euro(date, to_currency)
51
55
  end
@@ -54,8 +58,9 @@ module RkFxRates
54
58
  @fx_hash["data"].first[1].keys
55
59
  end
56
60
 
61
+ # returns collection in Ruby::Date format
57
62
  def available_dates
58
- return @fx_hash["data"].keys
63
+ @fx_hash["data"].keys
59
64
  end
60
65
 
61
66
  private
@@ -76,5 +81,6 @@ module RkFxRates
76
81
  store['rates'] = fx_hash
77
82
  end
78
83
  end
79
- end
80
- end
84
+
85
+ end # class ExchangeRate
86
+ end # module RkFxRates
@@ -1,11 +1,14 @@
1
1
  module RkFxRates
2
2
  module Provider
3
+
4
+ # Exchange rates over the last 90 days rom the European Central Bank
3
5
  class Ecb
4
6
 
5
7
  def self.data_url
6
8
  return 'http://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml'
7
9
  end
8
10
 
11
+ # convert xml to a defined default format
9
12
  # see rk_fx_rates.rb for data structure description
10
13
  def self.generate_fx_hash(data)
11
14
  fx_hash = Hash.new
@@ -1,3 +1,3 @@
1
1
  module RkFxRates
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -3,6 +3,9 @@ require 'spec_helper'
3
3
  describe RkFxRates do
4
4
 
5
5
  before(:each) do
6
+ # too slow
7
+ # File.delete('exchange_rates.store')
8
+ @date = Chronic.parse('last monday').to_date
6
9
  @fx_api = RkFxRates::ExchangeRate.new
7
10
  end
8
11
 
@@ -17,18 +20,16 @@ describe RkFxRates do
17
20
  # using the last monday to make sure the test runs with a weekday date
18
21
  # simplified case with Euro as the start currency
19
22
  it "should calcute the Exchange rate from EUR to USD" do
20
- date = Chronic.parse('last monday').to_date
21
- @fx_api.at( date, 'EUR', 'USD' ).should be > 1.2
23
+ @fx_api.at( @date, 'EUR', 'USD' ).should be > 1.2
22
24
  end
23
25
 
24
26
  it "should calculate the exchange rate from GBP to USD" do
25
- date = Chronic.parse('last monday').to_date
26
- @fx_api.at(date, 'GBP', 'USD').should be > 1.5
27
+ @fx_api.at( @date, 'GBP', 'USD').should be > 1.5
27
28
  end
28
29
 
29
30
  it "should calculate the exchange rate from EUR to EUR" do
30
31
  date = Chronic.parse('last monday').to_date
31
- @fx_api.at(date, 'EUR', 'EUR').should be == 1.0
32
+ @fx_api.at( @date, 'EUR', 'EUR').should be == 1.0
32
33
  end
33
34
 
34
35
  it "should provide a list with the available currencies" do
@@ -36,8 +37,7 @@ describe RkFxRates do
36
37
  end
37
38
 
38
39
  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)
40
+ @fx_api.available_dates.should include(@date)
41
41
  end
42
42
 
43
43
  context "with existing and current data" do
@@ -47,8 +47,7 @@ describe RkFxRates do
47
47
  end
48
48
 
49
49
  it "should not download the data again" do
50
- date = Chronic.parse('last monday').to_date
51
- @fx_api.at(date, 'GBP', 'USD').should be > 1.5
50
+ @fx_api.at( @date, 'GBP', 'USD').should be > 1.5
52
51
  end
53
52
 
54
53
  after(:each) do
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.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rainer Kuhn