google_currency 3.2.0 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 15465e69da6f84b9957b6cd166fa5623f8ddbf64
4
- data.tar.gz: 5dccac4429dc84a2ae1615d6cb43a45120f4445c
3
+ metadata.gz: 1b57390ef56dd1b049e7b5d9fd8a3ed893791779
4
+ data.tar.gz: 38469aad714942d2fb16afa1b933a2d31e6940b0
5
5
  SHA512:
6
- metadata.gz: c1b9bdf4d77d9e35b67d45b34f5c330dfad9c8737e9e078425b998cb8960569e1cdc7179d50d0d94d608e35e80266fa92bdd9bb8c4d6c48c2e4ec8928d0d17fa
7
- data.tar.gz: 39b45cf9d40d71e436a0d2444cf68b748567743a2a74355a5af4f4a8bf773ead3bccd46ebe44597e458307a88945ead011f535808a682d364d43cff33be24192
6
+ metadata.gz: 8207d9c3712b4e58da9080e9dcf1b1bf43620d615205435ebd36b2895824f99a155a52b3889bafa4729ee275d7e9c17d96728f65110ceeccc88de0188d805cf1
7
+ data.tar.gz: ed516c931481812b71dad0290ef1a657742eb743c2ff46699ec210a4c644e9dd3e23c4b8aba96a702269d6a893a5382139264b6af3e48c2dca66efc40e98c183
data/AUTHORS CHANGED
@@ -8,3 +8,4 @@ Lars Pind
8
8
  Shane Emmons
9
9
  sowenjub
10
10
  yinquanteo
11
+ Tarang Patel
@@ -1,3 +1,12 @@
1
+ 3.3.0
2
+ =====
3
+
4
+ - Update Money gem dep
5
+
6
+ 3.2.1
7
+ =====
8
+ - Increase precision of rates by using inverse reciprocals for certain currencyes
9
+
1
10
  3.0.0
2
11
  =====
3
12
 
data/README.md CHANGED
@@ -24,7 +24,8 @@ Usage
24
24
  money = Money.new(1_00, "USD") # amount is in cents
25
25
  money.exchange_to(:EUR)
26
26
 
27
- # or install the 'monetize' gem
27
+ # or install and use the 'monetize' gem
28
+ require 'monetize'
28
29
  money = 1.to_money(:USD)
29
30
  money.exchange_to(:EUR)
30
31
 
@@ -36,7 +37,25 @@ An `UnknownCurrency` will be thrown if `#exchange_to` is called with a
36
37
 
37
38
  A `GoogleCurrencyFetchError` will be thrown if there is an unknown issue with the Google Finance Converter API.
38
39
 
40
+ Caveats
41
+ -------
42
+
43
+ This gem uses [Google Finance Converter](https://www.google.com/finance/converter) under the hood.
44
+
45
+ Exchange rates are,
46
+
47
+ 1. Based on 1 unit of the original currency.
48
+ 1. Have a precision of 4 decimal places.
49
+
50
+ What this means is that if the JPY to USD exchange rate is 0.0083660,
51
+ Google will report the JPY to USD exchange rate as 0.0084.
52
+ As a result, a larger JPY to USD conversion such as 10000 JPY to USD would yield 84 USD instead of 83.66 USD.
53
+
54
+ Consequently, this means that small exchange rates will be imprecise.
55
+ For example, if the IDR to USD exchange rate were 0.00007761, Google will report it as 0.0001.
56
+ This means 100000 IDR would exchange to 10 USD instead of 7.76 USD.
57
+
39
58
  Copyright
40
59
  ---------
41
60
 
42
- Copyright (c) 2011 Shane Emmons. See {file:LICENSE} for details.
61
+ Copyright (c) 2011 Shane Emmons. See [LICENSE](LICENSE) for details.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "google_currency"
3
- s.version = "3.2.0"
3
+ s.version = "3.3.0"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = ["Shane Emmons"]
6
6
  s.email = ["semmons99@gmail.com"]
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.add_development_dependency "yard", ">= 0.5.8"
14
14
  s.add_development_dependency "ffi"
15
15
 
16
- s.add_dependency "money", "~> 6.5.0"
16
+ s.add_dependency "money", "~> 6.7"
17
17
 
18
18
  s.files = Dir.glob("{lib,spec}/**/*")
19
19
  s.files += %w(LICENSE README.md CHANGELOG.md AUTHORS)
@@ -1,4 +1,5 @@
1
1
  require 'money'
2
+ require 'money/rates_store/rate_removal_support'
2
3
  require 'open-uri'
3
4
 
4
5
  class Money
@@ -14,6 +15,7 @@ class Money
14
15
  SERVICE_HOST = "www.google.com"
15
16
  SERVICE_PATH = "/finance/converter"
16
17
 
18
+
17
19
  # @return [Hash] Stores the currently known rates.
18
20
  attr_reader :rates
19
21
 
@@ -43,6 +45,11 @@ class Money
43
45
  end
44
46
  end
45
47
 
48
+ def initialize(*)
49
+ super
50
+ @store.extend Money::RatesStore::RateRemovalSupport
51
+ end
52
+
46
53
  ##
47
54
  # Clears all rates stored in @rates
48
55
  #
@@ -53,9 +60,7 @@ class Money
53
60
  # @bank.get_rate(:USD, :EUR) #=> 0.776337241
54
61
  # @bank.flush_rates #=> {}
55
62
  def flush_rates
56
- @mutex.synchronize{
57
- @rates = {}
58
- }
63
+ store.clear_rates
59
64
  end
60
65
 
61
66
  ##
@@ -73,10 +78,7 @@ class Money
73
78
  # @bank.get_rate(:USD, :EUR) #=> 0.776337241
74
79
  # @bank.flush_rate(:USD, :EUR) #=> 0.776337241
75
80
  def flush_rate(from, to)
76
- key = rate_key_for(from, to)
77
- @mutex.synchronize{
78
- @rates.delete(key)
79
- }
81
+ store.remove_rate(from, to)
80
82
  end
81
83
 
82
84
  ##
@@ -94,10 +96,7 @@ class Money
94
96
  # @bank.get_rate(:USD, :EUR) #=> 0.776337241
95
97
  def get_rate(from, to)
96
98
  expire_rates
97
-
98
- @mutex.synchronize{
99
- @rates[rate_key_for(from, to)] ||= fetch_rate(from, to)
100
- }
99
+ store.get_rate(from, to) || store.add_rate(from, to, fetch_rate(from, to))
101
100
  end
102
101
 
103
102
  ##
@@ -124,9 +123,18 @@ class Money
124
123
  #
125
124
  # @return [BigDecimal] The requested rate.
126
125
  def fetch_rate(from, to)
126
+
127
127
  from, to = Currency.wrap(from), Currency.wrap(to)
128
+
128
129
  data = build_uri(from, to).read
129
- extract_rate(data)
130
+ rate = extract_rate(data);
131
+
132
+ if (rate < 0.1)
133
+ rate = 1/extract_rate(build_uri(to, from).read)
134
+ end
135
+
136
+ rate
137
+
130
138
  end
131
139
 
132
140
  ##
@@ -0,0 +1,27 @@
1
+ module Money::RatesStore
2
+ module RateRemovalSupport
3
+ # Remove a conversion rate and returns it. Uses +Mutex+ to synchronize data access.
4
+ #
5
+ # @param [String] currency_iso_from Currency to exchange from.
6
+ # @param [String] currency_iso_to Currency to exchange to.
7
+ #
8
+ # @return [Numeric]
9
+ #
10
+ # @example
11
+ # store = Money::RatesStore::Memory.new
12
+ # store.remove_rate("USD", "CAD")
13
+ # store.remove_rate("CAD", "USD")
14
+ def remove_rate(currency_iso_from, currency_iso_to)
15
+ transaction { index.delete rate_key_for(currency_iso_from, currency_iso_to) }
16
+ end
17
+
18
+ # Clears all conversion rates. Uses +Mutex+ to synchronize data access.
19
+ #
20
+ # @example
21
+ # store = Money::RatesStore::Memory.new
22
+ # store.clear_rates
23
+ def clear_rates
24
+ transaction { @index = {} }
25
+ end
26
+ end
27
+ end
@@ -46,7 +46,7 @@ describe "GoogleCurrency" do
46
46
 
47
47
  it "should store the rate for faster retreival" do
48
48
  @bank.get_rate('USD', 'EUR')
49
- expect(@bank.rates).to include('USD_TO_EUR')
49
+ expect(@bank.store.instance_variable_get("@index")).to include('USD_TO_EUR')
50
50
  end
51
51
 
52
52
  context "handles" do
@@ -80,7 +80,7 @@ describe "GoogleCurrency" do
80
80
  it "should empty @rates" do
81
81
  @bank.get_rate('USD', 'EUR')
82
82
  @bank.flush_rates
83
- expect(@bank.rates).to eq({})
83
+ expect(@bank.store.instance_variable_get("@index")).to eq({})
84
84
  end
85
85
  end
86
86
 
@@ -89,8 +89,8 @@ describe "GoogleCurrency" do
89
89
  @bank.get_rate('USD', 'EUR')
90
90
  @bank.get_rate('USD', 'JPY')
91
91
  @bank.flush_rate('USD', 'EUR')
92
- expect(@bank.rates).to include('USD_TO_JPY')
93
- expect(@bank.rates).to_not include('USD_TO_EUR')
92
+ expect(@bank.store.instance_variable_get("@index")).to include('USD_TO_JPY')
93
+ expect(@bank.store.instance_variable_get("@index")).to_not include('USD_TO_EUR')
94
94
  end
95
95
  end
96
96
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_currency
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Emmons
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-02 00:00:00.000000000 Z
11
+ date: 2016-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 6.5.0
61
+ version: '6.7'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 6.5.0
68
+ version: '6.7'
69
69
  description: GoogleCurrency extends Money::Bank::Base and gives you access to the
70
70
  current Google Currency exchange rates.
71
71
  email:
@@ -82,6 +82,7 @@ files:
82
82
  - Rakefile
83
83
  - google_currency.gemspec
84
84
  - lib/money/bank/google_currency.rb
85
+ - lib/money/rates_store/rate_removal_support.rb
85
86
  - spec/google_currency_with_json_spec.rb
86
87
  - spec/rates/error.html
87
88
  - spec/rates/sgd_to_usd.html
@@ -107,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
108
  version: '0'
108
109
  requirements: []
109
110
  rubyforge_project:
110
- rubygems_version: 2.2.2
111
+ rubygems_version: 2.4.5.1
111
112
  signing_key:
112
113
  specification_version: 4
113
114
  summary: Access the Google Currency exchange rate data.