eu_central_bank 0.3.7 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/CHANGELOG.md +4 -0
  2. data/lib/eu_central_bank.rb +17 -10
  3. metadata +4 -7
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # eu_central_bank changelog
2
2
 
3
+ ## 0.3.8 (Feb 12 2014)
4
+
5
+ * Updated money version
6
+
3
7
  ## 0.3.6 (Sep 4 2013)
4
8
 
5
9
  * Bank url change
@@ -11,7 +11,7 @@ class EuCentralBank < Money::Bank::VariableExchange
11
11
  attr_accessor :rates_updated_at
12
12
 
13
13
  ECB_RATES_URL = 'http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'
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
+ CURRENCIES = %w(USD JPY BGN CZK DKK GBP HUF ILS LTL PLN RON SEK CHF NOK HRK RUB TRY AUD BRL CAD CNY HKD IDR INR KRW MXN MYR NZD PHP SGD THB ZAR)
15
15
 
16
16
  def update_rates(cache=nil)
17
17
  update_parsed_rates(doc(cache))
@@ -40,18 +40,23 @@ class EuCentralBank < Money::Bank::VariableExchange
40
40
  def exchange_with(from, to_currency)
41
41
  rate = get_rate(from.currency, to_currency)
42
42
  unless rate
43
- from_base_rate = get_rate("EUR", from.currency)
44
- to_base_rate = get_rate("EUR", to_currency)
43
+ from_base_rate, to_base_rate = nil, nil
44
+ @mutex.synchronize {
45
+ from_base_rate = get_rate("EUR", from.currency, :without_mutex => true)
46
+ to_base_rate = get_rate("EUR", to_currency, :without_mutex => true)
47
+ }
45
48
  rate = to_base_rate / from_base_rate
46
49
  end
47
- Money.new(((Money::Currency.wrap(to_currency).subunit_to_unit.to_f / from.currency.subunit_to_unit.to_f) * from.cents * rate).round, to_currency)
50
+ Money.new(((BigDecimal(Money::Currency.wrap(to_currency).subunit_to_unit) / BigDecimal(from.currency.subunit_to_unit)) * from.cents * rate).round, to_currency)
48
51
  end
49
52
 
50
53
  protected
51
54
 
52
55
  def doc(cache)
53
56
  rates_source = !!cache ? cache : ECB_RATES_URL
54
- Nokogiri::XML(open(rates_source))
57
+ Nokogiri::XML(open(rates_source)).tap {|doc| doc.xpath('gesmes:Envelope/xmlns:Cube/xmlns:Cube//xmlns:Cube') }
58
+ rescue Nokogiri::XML::XPath::SyntaxError
59
+ Nokogiri::XML(open(ECB_RATES_URL))
55
60
  end
56
61
 
57
62
  def doc_from_s(content)
@@ -61,12 +66,14 @@ class EuCentralBank < Money::Bank::VariableExchange
61
66
  def update_parsed_rates(doc)
62
67
  rates = doc.xpath('gesmes:Envelope/xmlns:Cube/xmlns:Cube//xmlns:Cube')
63
68
 
64
- rates.each do |exchange_rate|
65
- rate = exchange_rate.attribute("rate").value.to_f
66
- currency = exchange_rate.attribute("currency").value
67
- add_rate("EUR", currency, rate)
69
+ @mutex.synchronize do
70
+ rates.each do |exchange_rate|
71
+ rate = BigDecimal(exchange_rate.attribute("rate").value)
72
+ currency = exchange_rate.attribute("currency").value
73
+ set_rate("EUR", currency, rate, :without_mutex => true)
74
+ end
75
+ set_rate("EUR", "EUR", 1, :without_mutex => true)
68
76
  end
69
- add_rate("EUR", "EUR", 1)
70
77
 
71
78
  rates_updated_at = doc.xpath('gesmes:Envelope/xmlns:Cube/xmlns:Cube/@time').first.value
72
79
  @rates_updated_at = Time.parse(rates_updated_at)
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.7
4
+ version: 0.3.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2013-09-04 00:00:00.000000000 Z
15
+ date: 2014-02-11 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: nokogiri
@@ -37,7 +37,7 @@ dependencies:
37
37
  requirements:
38
38
  - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
- version: 5.0.0
40
+ version: 6.0.1
41
41
  type: :runtime
42
42
  prerelease: false
43
43
  version_requirements: !ruby/object:Gem::Requirement
@@ -45,7 +45,7 @@ dependencies:
45
45
  requirements:
46
46
  - - ! '>='
47
47
  - !ruby/object:Gem::Version
48
- version: 5.0.0
48
+ version: 6.0.1
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: rspec
51
51
  requirement: !ruby/object:Gem::Requirement
@@ -118,9 +118,6 @@ 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: -2548782731518398539
124
121
  required_rubygems_version: !ruby/object:Gem::Requirement
125
122
  none: false
126
123
  requirements: