google_finance_currency_converter 0.3.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 44fc65187b8b654f07f0946df6d6f3a5a8857783
4
- data.tar.gz: 9b3daaeff75df2e81e0a9b295bfc0809d5b9b2b0
3
+ metadata.gz: ac20fa38292a74d3a96c645c6f16a94155401d16
4
+ data.tar.gz: d0db8141c56830069f4e4693fdc2fa87926a5963
5
5
  SHA512:
6
- metadata.gz: b45001163f59ad9874922be89ef50f53ca99bede5e85ee4bd43fb78e44c8fac04b3663978cc92546f7a7d59c699ef34f21b57e2cb458a2f971a16175ce2cbd2a
7
- data.tar.gz: 0a30c78d8fbcdf855538b15cb6484b2ec620994b6f29bd85ead28c0f92ababe3495a2144bd53484695d71f67bc739941606fdab52e25f1845bcc20de633cfb96
6
+ metadata.gz: a26ea4268ab608f2e655589115d662a312b520c268827007018e31f4b52209ef3c64ffa0b73b74fa38fb755c1167e5d1f60f9ace7567973712d4b7def68884d8
7
+ data.tar.gz: b61f875941ba99fa7e79c0317b2e5519c673fc2cb5db778560f607fd993946f2d98aa522b57f14de3d66e7ca651238e0cbcae1569bb2a6d1e6815db4f7ca8491
@@ -1,6 +1,6 @@
1
1
  = google_finance_currency_converter
2
2
 
3
- GoogleFinanceCurrencyConverter.new(:from => 'GBP', :to => 'BRL').rate # 2.784
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.3.1
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.3.1"
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 = "2013-08-01"
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.require_paths = ["lib"]
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 rate
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=1&from=#{@from}&to=#{@to}").read
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
- rate = response.scan(/<span class=bld>([^.]+(?:\.(?:\d+))?)/)
21
- raise "Rate not found" if rate.empty?
22
- rate[0][0].to_f
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 currency that returns an integer" do
6
- stub_converted_val_response(2)
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.rate.should == 2
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 work with currency that returns a float" do
13
- stub_converted_val_response(2.784)
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.rate.should == 2.784
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 'Rate not found' if the conversion doesn't exist" do
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.rate
33
- }.should raise_error("Rate not found")
37
+ converter.result
38
+ }.should raise_error("Result not found")
34
39
  end
35
40
  end
36
41
  end
@@ -210,7 +210,7 @@
210
210
  </select>
211
211
  </div>
212
212
  &nbsp;
213
- <div id=currency_converter_result>1 GBP = <span class=bld><converted_val> BRL</span>
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>
@@ -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 stub_converted_val_response(val)
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=1&from=GBP&to=BRL").
19
- to_return(:body => f.read.gsub("<converted_val>", val.to_s))
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.3.1
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: 2013-08-01 00:00:00.000000000 Z
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.0.5
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