google_currency 2.2.0 → 2.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.
- data/AUTHORS +2 -0
- data/CHANGELOG.md +5 -0
- data/google_currency.gemspec +3 -4
- data/lib/money/bank/google_currency.rb +6 -3
- data/spec/google_currency_with_json_spec.rb +15 -5
- metadata +6 -23
- data/spec/google_currency_with_yajl_spec.rb +0 -60
data/AUTHORS
CHANGED
data/CHANGELOG.md
CHANGED
data/google_currency.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "google_currency"
|
3
|
-
s.version = "2.
|
3
|
+
s.version = "2.3.0"
|
4
4
|
s.platform = Gem::Platform::RUBY
|
5
5
|
s.authors = ["Shane Emmons"]
|
6
6
|
s.email = ["semmons99@gmail.com"]
|
@@ -13,11 +13,10 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.add_development_dependency "rspec", ">= 2.0.0"
|
14
14
|
s.add_development_dependency "yard", ">= 0.5.8"
|
15
15
|
s.add_development_dependency "json", ">= 1.4.0"
|
16
|
-
s.add_development_dependency "yajl-ruby", ">= 1.0.0"
|
17
16
|
s.add_development_dependency "ffi"
|
18
17
|
|
19
|
-
s.add_dependency "money", "~> 5.1.
|
20
|
-
s.add_dependency "multi_json"
|
18
|
+
s.add_dependency "money", "~> 5.1.1"
|
19
|
+
s.add_dependency "multi_json"
|
21
20
|
|
22
21
|
s.files = Dir.glob("{lib,spec}/**/*")
|
23
22
|
s.files += %w(LICENSE README.md CHANGELOG.md AUTHORS)
|
@@ -8,6 +8,7 @@ class Money
|
|
8
8
|
|
9
9
|
SERVICE_HOST = "www.google.com"
|
10
10
|
SERVICE_PATH = "/ig/calculator"
|
11
|
+
EXPONENT_REGEXP = /10(x3c)?sup(x3e)?(?<exponent>-?\d+)(x3c)?\/sup(x3e)?/
|
11
12
|
|
12
13
|
# @return [Hash] Stores the currently known rates.
|
13
14
|
attr_reader :rates
|
@@ -107,6 +108,8 @@ class Money
|
|
107
108
|
#
|
108
109
|
# @return [Hash]
|
109
110
|
def fix_response_json_data(data)
|
111
|
+
data = data.force_encoding("ISO-8859-1").encode("UTF-8")
|
112
|
+
|
110
113
|
data.gsub!(/lhs:/, '"lhs":')
|
111
114
|
data.gsub!(/rhs:/, '"rhs":')
|
112
115
|
data.gsub!(/error:/, '"error":')
|
@@ -137,7 +140,7 @@ class Money
|
|
137
140
|
#
|
138
141
|
# @return [Boolean]
|
139
142
|
def complex_rate?(rhs)
|
140
|
-
rhs.match(
|
143
|
+
rhs.match(EXPONENT_REGEXP)
|
141
144
|
end
|
142
145
|
|
143
146
|
##
|
@@ -149,9 +152,9 @@ class Money
|
|
149
152
|
# @return [BigDecimal]
|
150
153
|
def decode_complex_rate(rhs)
|
151
154
|
rate = BigDecimal(rhs.match(/\d[\d\s]*\.?\d*/)[0])
|
152
|
-
power = rhs.match(
|
155
|
+
power = rhs.match(EXPONENT_REGEXP)
|
153
156
|
|
154
|
-
rate *
|
157
|
+
rate * BigDecimal("1E#{power[:exponent]}")
|
155
158
|
end
|
156
159
|
|
157
160
|
##
|
@@ -32,12 +32,22 @@ describe "GoogleCurrency" do
|
|
32
32
|
@bank.rates.should include('USD_TO_EUR')
|
33
33
|
end
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
context "handles" do
|
36
|
+
before :each do
|
37
|
+
@uri = double('uri')
|
38
|
+
@bank.stub(:build_uri){ |from,to| @uri }
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
+
it "Vietnamese Dong" do
|
42
|
+
# rhs decodes (after html entity decoding) to "4.8 x 10<sup>-5</sup> U.S. dollars"
|
43
|
+
@uri.stub(:read) { %q({lhs: "1 Vietnamese dong",rhs: "4.8 \x26#215; 10\x3csup\x3e-5\x3c/sup\x3e U.S. dollars",error: "",icc: true}) }
|
44
|
+
@bank.get_rate('VND', 'USD').should == BigDecimal("4.8E-5")
|
45
|
+
end
|
46
|
+
|
47
|
+
it "Indonesian Rupiah" do
|
48
|
+
@uri.stub(:read) { "{lhs: \"1 U.S. dollar\",rhs: \"10\xA0000 Indonesian rupiahs\",error: \"\",icc: true}" }
|
49
|
+
@bank.get_rate('IDR', 'USD').should == BigDecimal("0.1E5")
|
50
|
+
end
|
41
51
|
end
|
42
52
|
end
|
43
53
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_currency
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-10-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -59,22 +59,6 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 1.4.0
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: yajl-ruby
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
|
-
requirements:
|
67
|
-
- - ! '>='
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: 1.0.0
|
70
|
-
type: :development
|
71
|
-
prerelease: false
|
72
|
-
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ! '>='
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: 1.0.0
|
78
62
|
- !ruby/object:Gem::Dependency
|
79
63
|
name: ffi
|
80
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,7 +82,7 @@ dependencies:
|
|
98
82
|
requirements:
|
99
83
|
- - ~>
|
100
84
|
- !ruby/object:Gem::Version
|
101
|
-
version: 5.1.
|
85
|
+
version: 5.1.1
|
102
86
|
type: :runtime
|
103
87
|
prerelease: false
|
104
88
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -106,7 +90,7 @@ dependencies:
|
|
106
90
|
requirements:
|
107
91
|
- - ~>
|
108
92
|
- !ruby/object:Gem::Version
|
109
|
-
version: 5.1.
|
93
|
+
version: 5.1.1
|
110
94
|
- !ruby/object:Gem::Dependency
|
111
95
|
name: multi_json
|
112
96
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,7 +98,7 @@ dependencies:
|
|
114
98
|
requirements:
|
115
99
|
- - ! '>='
|
116
100
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
101
|
+
version: '0'
|
118
102
|
type: :runtime
|
119
103
|
prerelease: false
|
120
104
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -122,7 +106,7 @@ dependencies:
|
|
122
106
|
requirements:
|
123
107
|
- - ! '>='
|
124
108
|
- !ruby/object:Gem::Version
|
125
|
-
version:
|
109
|
+
version: '0'
|
126
110
|
description: GoogleCurrency extends Money::Bank::Base and gives you access to the
|
127
111
|
current Google Currency exchange rates.
|
128
112
|
email:
|
@@ -133,7 +117,6 @@ extra_rdoc_files: []
|
|
133
117
|
files:
|
134
118
|
- lib/money/bank/google_currency.rb
|
135
119
|
- spec/google_currency_with_json_spec.rb
|
136
|
-
- spec/google_currency_with_yajl_spec.rb
|
137
120
|
- spec/spec_helper.rb
|
138
121
|
- LICENSE
|
139
122
|
- README.md
|
@@ -1,60 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
require 'money'
|
4
|
-
require 'money/bank/google_currency'
|
5
|
-
|
6
|
-
require 'yajl'
|
7
|
-
MultiJson.engine = :yajl
|
8
|
-
|
9
|
-
describe "GoogleCurrency" do
|
10
|
-
before :each do
|
11
|
-
@bank = Money::Bank::GoogleCurrency.new
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "#get_rate" do
|
15
|
-
it "should use #fetch_rate when rate is unknown" do
|
16
|
-
@bank.should_receive(:fetch_rate).once
|
17
|
-
@bank.get_rate('USD', 'USD')
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should not use #fetch_rate when rate is known" do
|
21
|
-
@bank.get_rate('USD', 'USD')
|
22
|
-
@bank.should_not_receive(:fetch_rate)
|
23
|
-
@bank.get_rate('USD', 'USD')
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should return the correct rate" do
|
27
|
-
@bank.get_rate('USD', 'USD').should == 1.0
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should store the rate for faster retreival" do
|
31
|
-
@bank.get_rate('USD', 'EUR')
|
32
|
-
@bank.rates.should include('USD_TO_EUR')
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should handle complex rates" do
|
36
|
-
uri = double('uri')
|
37
|
-
@bank.stub(:build_uri){|from,to| uri }
|
38
|
-
uri.stub(:read) { %q({lhs: "1 Vietnamese dong",rhs: "4.8 \x26#215; 10\x3csup\x3e-5\x3c/sup\x3e U.S. dollars",error: "",icc: true}) }
|
39
|
-
@bank.get_rate('VND', 'USD').should == BigDecimal("0.48215105E1")
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "#flush_rates" do
|
44
|
-
it "should empty @rates" do
|
45
|
-
@bank.get_rate('USD', 'EUR')
|
46
|
-
@bank.flush_rates
|
47
|
-
@bank.rates.should == {}
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe "#flush_rate" do
|
52
|
-
it "should remove a specific rate from @rates" do
|
53
|
-
@bank.get_rate('USD', 'EUR')
|
54
|
-
@bank.get_rate('USD', 'JPY')
|
55
|
-
@bank.flush_rate('USD', 'EUR')
|
56
|
-
@bank.rates.should include('USD_TO_JPY')
|
57
|
-
@bank.rates.should_not include('USD_TO_EUR')
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|