goog_currency 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module GoogCurrency
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
data/lib/goog_currency.rb CHANGED
@@ -3,6 +3,7 @@ require 'rest_client'
3
3
  require 'json'
4
4
 
5
5
  module GoogCurrency
6
+ MILLION = 1_000_000
6
7
  def self.method_missing(meth, *args)
7
8
  from, to = meth.to_s.split("_to_")
8
9
 
@@ -25,7 +26,16 @@ module GoogCurrency
25
26
  response_hash = JSON.parse(response)
26
27
 
27
28
  if response_hash['error'].nil? or response_hash['error'] == ''
28
- response_hash['rhs'].to_f
29
+ case response_hash['rhs']
30
+ when /million/
31
+ response_hash['rhs'].to_f * MILLION
32
+ when /billion/
33
+ response_hash['rhs'].to_f * MILLION * 1_000
34
+ when /trillion/
35
+ response_hash['rhs'].to_f * MILLION * MILLION
36
+ else
37
+ response_hash['rhs'].to_f
38
+ end
29
39
  else
30
40
  raise Exception, "An error occurred: #{response_hash['error']}"
31
41
  end
@@ -40,6 +40,34 @@ describe "GoogCurrency" do
40
40
  # returned by the api
41
41
  expect { GoogCurrency.usd_to_inr(100) }.to_not raise_error
42
42
  end
43
+
44
+ it "converts millions" do
45
+ FakeWeb.register_uri(:get,
46
+ "http://www.google.com/ig/calculator?hl=en&q=500USD=?UGX",
47
+ :status => "200",
48
+ :body => '{lhs: "500 U.S. dollars",rhs: "1.28534704 million Ugandan shillings",error: "",icc: true}')
49
+ ugx = GoogCurrency.usd_to_ugx(500)
50
+ ugx.should == 1_285_347.04
51
+ end
52
+
53
+ it "converts billions" do
54
+ FakeWeb.register_uri(:get,
55
+ "http://www.google.com/ig/calculator?hl=en&q=500000USD=?UGX",
56
+ :status => "200",
57
+ :body => '{lhs: "500000 U.S. dollars",rhs: "1.28534704 billion Ugandan shillings",error: "",icc: true}')
58
+ ugx = GoogCurrency.usd_to_ugx(500_000)
59
+ ugx.should == 1_285_347_040.0
60
+ end
61
+
62
+ it "converts trillions" do
63
+ FakeWeb.register_uri(:get,
64
+ "http://www.google.com/ig/calculator?hl=en&q=500000000USD=?UGX",
65
+ :status => "200",
66
+ :body => '{lhs: "500000000 U.S. dollars",rhs: "1.28534704 trillion Ugandan shillings",error: "",icc: true}')
67
+ ugx = GoogCurrency.usd_to_ugx(500_000_000)
68
+ ugx.should == 1_285_347_040_000.0
69
+ end
70
+
43
71
  end
44
72
 
45
73
  describe "invalid currencies" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: goog_currency
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
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-08-12 00:00:00.000000000 Z
12
+ date: 2013-09-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -106,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
106
  segments:
107
107
  - 0
108
108
  version: '0'
109
- hash: -3404443824787550742
109
+ hash: 3660476117769931034
110
110
  required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  none: false
112
112
  requirements:
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  segments:
116
116
  - 0
117
117
  version: '0'
118
- hash: -3404443824787550742
118
+ hash: 3660476117769931034
119
119
  requirements: []
120
120
  rubyforge_project:
121
121
  rubygems_version: 1.8.25