google_finance_currency_converter 0.3.1 → 1.0.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 +4 -4
- data/README.rdoc +1 -1
- data/VERSION +1 -1
- data/google_finance_currency_converter.gemspec +5 -4
- data/lib/google_finance_currency_converter.rb +8 -5
- data/spec/google_finance_currency_converter_spec.rb +21 -16
- data/spec/helper/response.html +1 -1
- data/spec/spec_helper.rb +10 -4
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ac20fa38292a74d3a96c645c6f16a94155401d16
|
|
4
|
+
data.tar.gz: d0db8141c56830069f4e4693fdc2fa87926a5963
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a26ea4268ab608f2e655589115d662a312b520c268827007018e31f4b52209ef3c64ffa0b73b74fa38fb755c1167e5d1f60f9ace7567973712d4b7def68884d8
|
|
7
|
+
data.tar.gz: b61f875941ba99fa7e79c0317b2e5519c673fc2cb5db778560f607fd993946f2d98aa522b57f14de3d66e7ca651238e0cbcae1569bb2a6d1e6815db4f7ca8491
|
data/README.rdoc
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
= google_finance_currency_converter
|
|
2
2
|
|
|
3
|
-
GoogleFinanceCurrencyConverter.new(:from => 'GBP', :to => 'BRL').
|
|
3
|
+
GoogleFinanceCurrencyConverter.new(:from => 'GBP', :to => 'BRL', :amount => 1).result # 2.784
|
|
4
4
|
|
|
5
5
|
== Contributing to google_finance_currency_converter
|
|
6
6
|
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
1.0.0
|
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
|
5
|
+
# stub: google_finance_currency_converter 1.0.0 ruby lib
|
|
5
6
|
|
|
6
7
|
Gem::Specification.new do |s|
|
|
7
8
|
s.name = "google_finance_currency_converter"
|
|
8
|
-
s.version = "0.
|
|
9
|
+
s.version = "1.0.0"
|
|
9
10
|
|
|
10
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
12
|
+
s.require_paths = ["lib"]
|
|
11
13
|
s.authors = ["Pedro Menezes"]
|
|
12
|
-
s.date = "
|
|
14
|
+
s.date = "2014-05-19"
|
|
13
15
|
s.description = "a wrapper for google finance currency converter"
|
|
14
16
|
s.email = "pedrojudo@gmail.com"
|
|
15
17
|
s.extra_rdoc_files = [
|
|
@@ -34,8 +36,7 @@ Gem::Specification.new do |s|
|
|
|
34
36
|
]
|
|
35
37
|
s.homepage = "http://github.com/pedromenezes/google_finance_currency_converter"
|
|
36
38
|
s.licenses = ["MIT"]
|
|
37
|
-
s.
|
|
38
|
-
s.rubygems_version = "2.0.5"
|
|
39
|
+
s.rubygems_version = "2.2.2"
|
|
39
40
|
s.summary = "a wrapper for google finance currency converter"
|
|
40
41
|
|
|
41
42
|
if s.respond_to? :specification_version then
|
|
@@ -4,21 +4,24 @@ class GoogleFinanceCurrencyConverter
|
|
|
4
4
|
def initialize(params={})
|
|
5
5
|
@from = params[:from]
|
|
6
6
|
@to = params[:to]
|
|
7
|
+
@amount = params[:amount]
|
|
8
|
+
@amount = 1 if @amount == nil
|
|
7
9
|
raise "Same code" if @from == @to
|
|
8
10
|
end
|
|
9
11
|
|
|
10
|
-
def
|
|
12
|
+
def result
|
|
13
|
+
return 0 if @amount == 0
|
|
11
14
|
parse_response(request)
|
|
12
15
|
end
|
|
13
16
|
|
|
14
17
|
private
|
|
15
18
|
def request
|
|
16
|
-
open("http://www.google.com/finance/converter?a
|
|
19
|
+
open("http://www.google.com/finance/converter?a=#{@amount}&from=#{@from}&to=#{@to}").read
|
|
17
20
|
end
|
|
18
21
|
|
|
19
22
|
def parse_response(response)
|
|
20
|
-
|
|
21
|
-
raise "
|
|
22
|
-
|
|
23
|
+
scanned_result = response.scan(/<span class=bld>([^.]+(?:\.(?:\d+))?)/)
|
|
24
|
+
raise "Result not found" if scanned_result.empty?
|
|
25
|
+
scanned_result[0][0].to_f
|
|
23
26
|
end
|
|
24
27
|
end
|
|
@@ -2,35 +2,40 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
|
2
2
|
|
|
3
3
|
describe GoogleFinanceCurrencyConverter do
|
|
4
4
|
describe "conversion" do
|
|
5
|
-
it "should work with
|
|
6
|
-
|
|
5
|
+
it "should work with valid values" do
|
|
6
|
+
stub_converted_response_value(:amount_to_convert => 2, :response_value => 4.784)
|
|
7
7
|
|
|
8
|
-
converter = GoogleFinanceCurrencyConverter.new(:from => 'GBP', :to => 'BRL')
|
|
9
|
-
converter.
|
|
8
|
+
converter = GoogleFinanceCurrencyConverter.new(:from => 'GBP', :to => 'BRL', :amount => 2)
|
|
9
|
+
converter.result.should == 4.784
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "should return 0 when user wants to convert 0" do
|
|
13
|
+
converter = GoogleFinanceCurrencyConverter.new(:from => 'GBP', :to => 'BRL', :amount => 0)
|
|
14
|
+
converter.result.should == 0
|
|
10
15
|
end
|
|
11
|
-
|
|
12
|
-
it "should
|
|
13
|
-
|
|
16
|
+
|
|
17
|
+
it "should set amount to 1 when amount is nil" do
|
|
18
|
+
stub_converted_response_value(:amount_to_convert => 1, :response_value => 4.784)
|
|
14
19
|
|
|
15
20
|
converter = GoogleFinanceCurrencyConverter.new(:from => 'GBP', :to => 'BRL')
|
|
16
|
-
converter.
|
|
21
|
+
converter.result.should == 4.784
|
|
17
22
|
end
|
|
18
23
|
end
|
|
19
|
-
|
|
24
|
+
|
|
20
25
|
describe "raising error" do
|
|
21
26
|
it "should raise 'Same code' if from and to codes are the same" do
|
|
22
27
|
lambda {
|
|
23
|
-
converter = GoogleFinanceCurrencyConverter.new(:from => 'BRL', :to => 'BRL')
|
|
28
|
+
converter = GoogleFinanceCurrencyConverter.new(:from => 'BRL', :to => 'BRL', :amount => 1)
|
|
24
29
|
}.should raise_error("Same code")
|
|
25
30
|
end
|
|
26
|
-
|
|
27
|
-
it "should raise '
|
|
31
|
+
|
|
32
|
+
it "should raise 'Result not found' if the conversion doesn't exist" do
|
|
28
33
|
stub_error_response()
|
|
29
|
-
|
|
30
|
-
converter = GoogleFinanceCurrencyConverter.new(:from => 'BRL', :to => 'ALL')
|
|
34
|
+
|
|
35
|
+
converter = GoogleFinanceCurrencyConverter.new(:from => 'BRL', :to => 'ALL', :amount => 1)
|
|
31
36
|
lambda {
|
|
32
|
-
converter.
|
|
33
|
-
}.should raise_error("
|
|
37
|
+
converter.result
|
|
38
|
+
}.should raise_error("Result not found")
|
|
34
39
|
end
|
|
35
40
|
end
|
|
36
41
|
end
|
data/spec/helper/response.html
CHANGED
|
@@ -210,7 +210,7 @@
|
|
|
210
210
|
</select>
|
|
211
211
|
</div>
|
|
212
212
|
|
|
213
|
-
<div id=currency_converter_result>
|
|
213
|
+
<div id=currency_converter_result><amount_to_convert> GBP = <span class=bld><response_value> BRL</span>
|
|
214
214
|
<input type=submit value="Convert">
|
|
215
215
|
</div>
|
|
216
216
|
</form>
|
data/spec/spec_helper.rb
CHANGED
|
@@ -10,13 +10,19 @@ require 'google_finance_currency_converter'
|
|
|
10
10
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
|
11
11
|
|
|
12
12
|
RSpec.configure do |config|
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
def
|
|
16
|
+
def stub_converted_response_value(params)
|
|
17
|
+
amount_to_convert = params[:amount_to_convert] or 0
|
|
18
|
+
response_value = params[:response_value] or 0
|
|
19
|
+
|
|
17
20
|
File.open(File.expand_path(File.dirname(__FILE__) + '/helper/response.html'), 'r') do |f|
|
|
18
|
-
stub_request(:get, "http://www.google.com/finance/converter?a
|
|
19
|
-
to_return(
|
|
21
|
+
stub_request(:get, "http://www.google.com/finance/converter?a=#{amount_to_convert}&from=GBP&to=BRL").
|
|
22
|
+
to_return(
|
|
23
|
+
:body => f.read.gsub("<amount_to_convert>", amount_to_convert.to_s)
|
|
24
|
+
.gsub("<response_value>", response_value.to_s)
|
|
25
|
+
)
|
|
20
26
|
end
|
|
21
27
|
end
|
|
22
28
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: google_finance_currency_converter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Pedro Menezes
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2014-05-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rspec
|
|
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
108
108
|
version: '0'
|
|
109
109
|
requirements: []
|
|
110
110
|
rubyforge_project:
|
|
111
|
-
rubygems_version: 2.
|
|
111
|
+
rubygems_version: 2.2.2
|
|
112
112
|
signing_key:
|
|
113
113
|
specification_version: 4
|
|
114
114
|
summary: a wrapper for google finance currency converter
|