eu_central_bank 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,50 +1,50 @@
1
- = eu_central_bank changelog
1
+ # eu_central_bank changelog
2
2
 
3
- == 0.3.0 (Jan 29 2012)
3
+ ## 0.3.0 (Jan 29 2012)
4
4
 
5
5
  * Updated Money dependency to 4.0.1
6
6
  * Fixed deprecated rake tasks
7
7
 
8
- == 0.2.4 (Sep 14 2011)
8
+ ## 0.2.4 (Sep 14 2011)
9
9
 
10
10
  * Merged pull request #6: support currencies without subunits
11
11
 
12
- == 0.2.3 (Sep 8 2011)
12
+ ## 0.2.3 (Sep 8 2011)
13
13
 
14
14
  * Updated Nokogiri dependency to 1.5.0
15
15
 
16
- == 0.2.2 (Jul 13 2011)
16
+ ## 0.2.2 (Jul 13 2011)
17
17
 
18
18
  * Fixed #2 versioning bug
19
19
 
20
- == 0.2.1 (Jul 13 2011-yanked)
20
+ ## 0.2.1 (Jul 13 2011-yanked)
21
21
 
22
22
  * Updated dependencies to run with Money 3.7.x
23
23
 
24
- == 0.2.0 (Feb 19 2011)
24
+ ## 0.2.0 (Feb 19 2011)
25
25
 
26
26
  * Changed to use rounding instead of flooring dues to issues with negative number amounts
27
27
 
28
- == 0.1.5 (Jan 18 2011)
28
+ ## 0.1.5 (Jan 18 2011)
29
29
 
30
30
  * Updated the money dependency on the gemspec
31
31
 
32
- == 0.1.4 (Jan 18 2011)
32
+ ## 0.1.4 (Jan 18 2011)
33
33
 
34
34
  * Removed the Estonian Kroon from the list of currencies as EU Central Bank does not list it anymore
35
35
 
36
- == 0.1.3 (December 18 2010)
36
+ ## 0.1.3 (December 18 2010)
37
37
 
38
38
  * Fixed the gemspec bug
39
39
 
40
- == 0.1.2 (December 15 2010)
40
+ ## 0.1.2 (December 15 2010)
41
41
 
42
42
  * Clean up dependencies
43
43
 
44
- == 0.1.1 (July 17 2010)
44
+ ## 0.1.1 (July 17 2010)
45
45
 
46
46
  * Added the exchange_with method from money gem
47
47
 
48
- == 0.1.0 (April 21 2010)
48
+ ## 0.1.0 (April 21 2010)
49
49
 
50
50
  * Initial gem release
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # eu_central_bank
2
+
3
+ {<img src="https://secure.travis-ci.org/RubyMoney/eu_central_bank.png?branch=master" alt="Build Status" />}[http://travis-ci.org/RubyMoney/eu_central_bank]
4
+
5
+ ## Introduction
6
+
7
+ This gem downloads the exchange rates from the European Central Bank. You can calculate exchange rates with it. It is compatible with the money gem.
8
+
9
+ ## Installation
10
+
11
+ ```
12
+ gem install eu_central_bank
13
+ ```
14
+
15
+ ## Dependencies
16
+
17
+ - nokogiri
18
+ - money
19
+
20
+ ## Usage
21
+
22
+ With the gem, you do not need to manually add exchange rates. Calling update_rates will download the rates from the European Central Bank. The API is the same as the money gem. Feel free to use Money objects with the bank.
23
+
24
+ ``` ruby
25
+ eu_bank = EuCentralBank.new
26
+ Money.default_bank = eu_bank
27
+ money1 = Money.new(10)
28
+ money1.bank # eu_bank
29
+
30
+ # call this before calculating exchange rates
31
+ # this will download the rates from ECB
32
+ eu_bank.update_rates
33
+
34
+ # exchange 100 CAD to USD
35
+ # API is the same as the money gem
36
+ eu_bank.exchange(100, "CAD", "USD") # Money.new(80, "USD")
37
+ Money.us_dollar(100).exchange_to("CAD") # Money.new(124, "CAD")
38
+
39
+ # using the new exchange_with method
40
+ eu_bank.exchange_with(Money.new(100, "CAD"), "USD") # Money.new(80, "USD")
41
+ ```
42
+
43
+ For performance reasons, you may prefer to read from a file instead. Furthermore, ECB publishes their rates daily. It makes sense to save the rates in a file to read from. It also adds an __update_at__ field so that you can manage the update.
44
+
45
+ ``` ruby
46
+ # cached location
47
+ cache = "/some/file/location/exchange_rates.xml"
48
+
49
+ # saves the rates in a specified location
50
+ eu_bank.save_rates(cache)
51
+
52
+ # reads the rates from the specified location
53
+ eu_bank.update_rates(cache)
54
+
55
+ if !@bank.rates_updated_at || @bank.rates_updated_at < Time.now - 1.days
56
+ @bank.save_rates(cache)
57
+ @bank.update_rates(cache)
58
+ end
59
+
60
+ # exchange 100 CAD to USD as usual
61
+ eu_bank.exchange_with(Money.new(100, "CAD"), "USD") # Money.new(80, "USD")
62
+ ```
63
+
64
+ ## Note on Patches/Pull Requests
65
+
66
+ - Fork the project.
67
+ - Make your feature addition or bug fix.
68
+ - Add tests for it. This is important so I don't break it in a future version unintentionally.
69
+ - Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
70
+
71
+ ## Copyright
72
+
73
+ Copyright (c) 2010-2013 RubyMoney. See LICENSE for details.
@@ -8,12 +8,13 @@ class InvalidCache < StandardError ; end
8
8
  class EuCentralBank < Money::Bank::VariableExchange
9
9
 
10
10
  attr_accessor :last_updated
11
+ attr_accessor :rates_updated_at
11
12
 
12
13
  ECB_RATES_URL = 'http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml'
13
14
  CURRENCIES = %w(USD JPY BGN CZK DKK GBP HUF ILS 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)
14
15
 
15
16
  def update_rates(cache=nil)
16
- update_parsed_rates(exchange_rates(cache))
17
+ update_parsed_rates(doc(cache))
17
18
  end
18
19
 
19
20
  def save_rates(cache)
@@ -25,7 +26,7 @@ class EuCentralBank < Money::Bank::VariableExchange
25
26
  end
26
27
 
27
28
  def update_rates_from_s(content)
28
- update_parsed_rates(exchange_rates_from_s(content))
29
+ update_parsed_rates(doc_from_s(content))
29
30
  end
30
31
 
31
32
  def save_rates_to_s
@@ -48,24 +49,28 @@ class EuCentralBank < Money::Bank::VariableExchange
48
49
 
49
50
  protected
50
51
 
51
- def exchange_rates(cache=nil)
52
+ def doc(cache)
52
53
  rates_source = !!cache ? cache : ECB_RATES_URL
53
- doc = Nokogiri::XML(open(rates_source))
54
- doc.xpath('gesmes:Envelope/xmlns:Cube/xmlns:Cube//xmlns:Cube')
54
+ Nokogiri::XML(open(rates_source))
55
55
  end
56
56
 
57
- def exchange_rates_from_s(content)
58
- doc = Nokogiri::XML(content)
59
- doc.xpath('gesmes:Envelope/xmlns:Cube/xmlns:Cube//xmlns:Cube')
57
+ def doc_from_s(content)
58
+ Nokogiri::XML(content)
60
59
  end
61
60
 
62
- def update_parsed_rates(rates)
61
+ def update_parsed_rates(doc)
62
+ rates = doc.xpath('gesmes:Envelope/xmlns:Cube/xmlns:Cube//xmlns:Cube')
63
+
63
64
  rates.each do |exchange_rate|
64
65
  rate = exchange_rate.attribute("rate").value.to_f
65
66
  currency = exchange_rate.attribute("currency").value
66
67
  add_rate("EUR", currency, rate)
67
68
  end
68
69
  add_rate("EUR", "EUR", 1)
70
+
71
+ rates_updated_at = doc.xpath('gesmes:Envelope/xmlns:Cube/xmlns:Cube/@time').first.value
72
+ @rates_updated_at = Time.parse(rates_updated_at)
73
+
69
74
  @last_updated = Time.now
70
75
  end
71
76
  end
metadata CHANGED
@@ -1,18 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eu_central_bank
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Wong Liang Zan
9
9
  - Shane Emmons
10
- - Thorsten Bottger
10
+ - Thorsten Böttger
11
11
  - Jonathan Eisenstein
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2013-02-05 00:00:00.000000000 Z
15
+ date: 2013-08-16 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: nokogiri
@@ -103,9 +103,9 @@ extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
105
  - lib/eu_central_bank.rb
106
- - CHANGELOG.rdoc
106
+ - CHANGELOG.md
107
107
  - LICENSE
108
- - README.rdoc
108
+ - README.md
109
109
  homepage: http://github.com/RubyMoney/eu_central_bank
110
110
  licenses: []
111
111
  post_install_message:
@@ -118,6 +118,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
118
118
  - - ! '>='
119
119
  - !ruby/object:Gem::Version
120
120
  version: '0'
121
+ segments:
122
+ - 0
123
+ hash: -209299811093199673
121
124
  required_rubygems_version: !ruby/object:Gem::Requirement
122
125
  none: false
123
126
  requirements:
@@ -126,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
129
  version: 1.3.6
127
130
  requirements: []
128
131
  rubyforge_project:
129
- rubygems_version: 1.8.24
132
+ rubygems_version: 1.8.25
130
133
  signing_key:
131
134
  specification_version: 3
132
135
  summary: Calculates exchange rates based on rates from european central bank. Money
data/README.rdoc DELETED
@@ -1,61 +0,0 @@
1
- = eu_central_bank
2
-
3
- {<img src="https://secure.travis-ci.org/RubyMoney/eu_central_bank.png?branch=master" alt="Build Status" />}[http://travis-ci.org/RubyMoney/eu_central_bank]
4
-
5
- == Introduction
6
-
7
- This gem downloads the exchange rates from the European Central Bank. You can calculate exchange rates with it. It is compatible with the money gem.
8
-
9
- == Installation
10
-
11
- $ gem install eu_central_bank
12
-
13
- == Dependencies
14
-
15
- * nokogiri
16
- * money
17
-
18
- == Usage
19
-
20
- With the gem, you do not need to manually add exchange rates. Calling update_rates will download the rates from the European Central Bank. The API is the same as the money gem. Feel free to use Money objects with the bank.
21
-
22
- eu_bank = EuCentralBank.new
23
- Money.default_bank = eu_bank
24
- money1 = Money.new(10)
25
- money1.bank # eu_bank
26
-
27
- # call this before calculating exchange rates
28
- # this will download the rates from ECB
29
- eu_bank.update_rates
30
-
31
- # exchange 100 CAD to USD
32
- # API is the same as the money gem
33
- eu_bank.exchange(100, "CAD", "USD") # Money.new(80, "USD")
34
- Money.us_dollar(100).exchange_to("CAD") # Money.new(124, "CAD")
35
-
36
- # using the new exchange_with method
37
- eu_bank.exchange_with(Money.new(100, "CAD"), "USD") # Money.new(80, "USD")
38
-
39
- For performance reasons, you may prefer to read from a file instead. Furthermore, ECB publishes their rates daily. It makes sense to save the rates in a file to read from.
40
-
41
- # saves the rates in a specified location
42
- eu_bank.save_rates("/some/file/location/exchange_rates.xml")
43
-
44
- # reads the rates from the specified location
45
- eu_bank.update_rates("/some/file/location/exchange_rates.xml")
46
-
47
- # exchange 100 CAD to USD as usual
48
- eu_bank.exchange_with(Money.new(100, "CAD"), "USD") # Money.new(80, "USD")
49
-
50
- == Note on Patches/Pull Requests
51
-
52
- * Fork the project.
53
- * Make your feature addition or bug fix.
54
- * Add tests for it. This is important so I don't break it in a
55
- future version unintentionally.
56
- * Commit, do not mess with rakefile, version, or history.
57
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
58
-
59
- == Copyright
60
-
61
- Copyright (c) 2010 RubyMoney. See LICENSE for details.