eu_central_bank 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/eu_central_bank.rb +25 -6
  2. metadata +38 -13
@@ -7,16 +7,13 @@ class InvalidCache < StandardError ; end
7
7
 
8
8
  class EuCentralBank < Money::Bank::VariableExchange
9
9
 
10
+ attr_accessor :last_updated
11
+
10
12
  ECB_RATES_URL = 'http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml'
11
13
  CURRENCIES = %w(USD JPY BGN CZK DKK GBP HUF LTL LVL PLN RON SEK CHF NOK HRK RUB TRY AUD BRL CAD CNY HKD IDR INR KRW MXN MYR NZD PHP SGD THB ZAR)
12
14
 
13
15
  def update_rates(cache=nil)
14
- exchange_rates(cache).each do |exchange_rate|
15
- rate = exchange_rate.attribute("rate").value.to_f
16
- currency = exchange_rate.attribute("currency").value
17
- add_rate("EUR", currency, rate)
18
- end
19
- add_rate("EUR", "EUR", 1)
16
+ update_parsed_rates(exchange_rates(cache))
20
17
  end
21
18
 
22
19
  def save_rates(cache)
@@ -27,6 +24,14 @@ class EuCentralBank < Money::Bank::VariableExchange
27
24
  end
28
25
  end
29
26
 
27
+ def update_rates_from_s(content)
28
+ update_parsed_rates(exchange_rates_from_s(content))
29
+ end
30
+
31
+ def save_rates_to_s
32
+ open(ECB_RATES_URL).read
33
+ end
34
+
30
35
  def exchange(cents, from_currency, to_currency)
31
36
  exchange_with(Money.new(cents, from_currency), to_currency)
32
37
  end
@@ -49,4 +54,18 @@ class EuCentralBank < Money::Bank::VariableExchange
49
54
  doc.xpath('gesmes:Envelope/xmlns:Cube/xmlns:Cube//xmlns:Cube')
50
55
  end
51
56
 
57
+ def exchange_rates_from_s(content)
58
+ doc = Nokogiri::XML(content)
59
+ doc.xpath('gesmes:Envelope/xmlns:Cube/xmlns:Cube//xmlns:Cube')
60
+ end
61
+
62
+ def update_parsed_rates(rates)
63
+ rates.each do |exchange_rate|
64
+ rate = exchange_rate.attribute("rate").value.to_f
65
+ currency = exchange_rate.attribute("currency").value
66
+ add_rate("EUR", currency, rate)
67
+ end
68
+ add_rate("EUR", "EUR", 1)
69
+ @last_updated = Time.now
70
+ end
52
71
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eu_central_bank
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-01-30 00:00:00.000000000 Z
14
+ date: 2012-05-06 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: nokogiri
18
- requirement: &70140813631300 !ruby/object:Gem::Requirement
18
+ requirement: !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,10 +23,15 @@ dependencies:
23
23
  version: '0'
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *70140813631300
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ! '>='
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
27
32
  - !ruby/object:Gem::Dependency
28
33
  name: money
29
- requirement: &70140813630200 !ruby/object:Gem::Requirement
34
+ requirement: !ruby/object:Gem::Requirement
30
35
  none: false
31
36
  requirements:
32
37
  - - ~>
@@ -34,10 +39,15 @@ dependencies:
34
39
  version: 4.0.1
35
40
  type: :runtime
36
41
  prerelease: false
37
- version_requirements: *70140813630200
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 4.0.1
38
48
  - !ruby/object:Gem::Dependency
39
49
  name: rspec
40
- requirement: &70140813629320 !ruby/object:Gem::Requirement
50
+ requirement: !ruby/object:Gem::Requirement
41
51
  none: false
42
52
  requirements:
43
53
  - - ! '>='
@@ -45,10 +55,15 @@ dependencies:
45
55
  version: 2.0.0
46
56
  type: :development
47
57
  prerelease: false
48
- version_requirements: *70140813629320
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: 2.0.0
49
64
  - !ruby/object:Gem::Dependency
50
65
  name: rr
51
- requirement: &70140813628040 !ruby/object:Gem::Requirement
66
+ requirement: !ruby/object:Gem::Requirement
52
67
  none: false
53
68
  requirements:
54
69
  - - ! '>='
@@ -56,10 +71,15 @@ dependencies:
56
71
  version: '0'
57
72
  type: :development
58
73
  prerelease: false
59
- version_requirements: *70140813628040
74
+ version_requirements: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
60
80
  - !ruby/object:Gem::Dependency
61
81
  name: shoulda
62
- requirement: &70140813626920 !ruby/object:Gem::Requirement
82
+ requirement: !ruby/object:Gem::Requirement
63
83
  none: false
64
84
  requirements:
65
85
  - - ! '>='
@@ -67,7 +87,12 @@ dependencies:
67
87
  version: '0'
68
88
  type: :development
69
89
  prerelease: false
70
- version_requirements: *70140813626920
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
71
96
  description: This gem reads exchange rates from the european central bank website.
72
97
  It uses it to calculates exchange rates. It is compatible with the money gem
73
98
  email:
@@ -100,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
125
  version: 1.3.6
101
126
  requirements: []
102
127
  rubyforge_project:
103
- rubygems_version: 1.8.11
128
+ rubygems_version: 1.8.21
104
129
  signing_key:
105
130
  specification_version: 3
106
131
  summary: Calculates exchange rates based on rates from european central bank. Money