goog_currency 0.0.1 → 0.0.2

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.
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Girish S
1
+ Copyright (c) 2013 Girish Sonawane
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  A simple Ruby interface for currency conversion using Google API. Uses http://www.google.com/ig/calculator?hl=en&q=100USD=?INR
4
4
 
5
+ Current version: 0.0.2
6
+
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
@@ -20,8 +22,9 @@ Or install it yourself as:
20
22
 
21
23
  Sample usage
22
24
 
23
- usd = GoogCurrency.usd_to_inr(1)
24
- gbp = GoogCurrency.usd_to_gbp(1)
25
+ rupees = GoogCurrency.usd_to_inr(1)
26
+ pounds = GoogCurrency.usd_to_gbp(1)
27
+ yen = GoogCurrency.gbp_to_jpy(1)
25
28
 
26
29
  Throws GoogCurrency::Exception in case of any error.
27
30
 
@@ -34,3 +37,9 @@ Throws GoogCurrency::NoMethodException if conversion method syntax is invalid.
34
37
  3. Commit your changes (`git commit -am 'Add some feature'`)
35
38
  4. Push to the branch (`git push origin my-new-feature`)
36
39
  5. Create new Pull Request
40
+
41
+ ## Licence
42
+ MIT License
43
+
44
+ Copyright (c) 2013 Girish Sonawane
45
+
@@ -8,7 +8,7 @@ Gem::Specification.new do |gem|
8
8
  gem.version = GoogCurrency::VERSION
9
9
  gem.authors = ["Girish S"]
10
10
  gem.email = ["girish.sonawane@gmail.com"]
11
- gem.description = %q{Gem for currency conversion using Google API}
11
+ gem.description = %q{Ruby Gem for currency conversion using Google API}
12
12
  gem.summary = %q{Simple Ruby interface to Google Currency API}
13
13
  gem.add_runtime_dependency 'rest-client', '~> 1.6.7'
14
14
  gem.add_runtime_dependency 'json', '~> 1.7.5'
@@ -7,7 +7,7 @@ module GoogCurrency
7
7
  from, to = meth.to_s.split("_to_")
8
8
 
9
9
  if from.nil? or to.nil?
10
- raise GoogCurrency::NoMethodException, "GoogCurrency accepts methods in 'usd_to_inr' or 'gbp_to_usd' format"
10
+ raise NoMethodException, "GoogCurrency accepts methods in 'usd_to_inr' or 'gbp_to_usd' format"
11
11
  end
12
12
 
13
13
  response = RestClient.get("http://www.google.com/ig/calculator?hl=en&q=#{args.first}#{from.upcase}=?#{to.upcase}").body
@@ -17,9 +17,19 @@ module GoogCurrency
17
17
  response_hash = JSON.parse(response)
18
18
 
19
19
  if response_hash['error'].nil? or response_hash['error'] == ''
20
- response_hash['rhs'].to_f
20
+ #
21
+ # Remove unicode character used as thousands separator by the Google API
22
+ # Thanks to Nathan Long, http://stackoverflow.com/a/9420531
23
+ #
24
+ encoding_options = {
25
+ :invalid => :replace, # Replace invalid byte sequences
26
+ :undef => :replace, # Replace anything not defined in ASCII
27
+ :replace => '', # Use a blank for those replacements
28
+ :universal_newline => true # Always break lines with \n
29
+ }
30
+ response_hash['rhs'].encode(Encoding.find('ASCII'), encoding_options).to_f
21
31
  else
22
- raise GoogCurrency::Exception, "An error occurred: #{response_hash['error']}"
32
+ raise Exception, "An error occurred: #{response_hash['error']}"
23
33
  end
24
34
  end
25
35
 
@@ -1,3 +1,3 @@
1
1
  module GoogCurrency
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -7,6 +7,10 @@ valid_response =<<-VALID
7
7
  {lhs: "1 U.S. dollar",rhs: "54.836587 Indian rupees",error: "",icc: true}
8
8
  VALID
9
9
 
10
+ valid100_response =<<-VALID_100
11
+ {lhs: "100 U.S. dollar",rhs: "5\u0080483.6587 Indian rupees",error: "",icc: true}
12
+ VALID_100
13
+
10
14
  invalid_response =<<-INVALID
11
15
  {lhs: "",rhs: "",error: "4",icc: false}
12
16
  INVALID
@@ -21,6 +25,15 @@ describe "GoogCurrency" do
21
25
  usd = GoogCurrency.usd_to_inr(1)
22
26
  usd.should == 54.836587
23
27
  end
28
+
29
+ it "ignores thousands separator correctly" do
30
+ FakeWeb.register_uri(:get,
31
+ "http://www.google.com/ig/calculator?hl=en&q=100USD=?INR",
32
+ :status => "200",
33
+ :body => valid100_response)
34
+ usd = GoogCurrency.usd_to_inr(100)
35
+ usd.should == 5483.6587
36
+ end
24
37
  end
25
38
 
26
39
  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: 0.0.1
4
+ version: 0.0.2
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: 2012-11-07 00:00:00.000000000 Z
12
+ date: 2013-01-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -75,7 +75,7 @@ dependencies:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
77
  version: 1.3.0
78
- description: Gem for currency conversion using Google API
78
+ description: Ruby Gem for currency conversion using Google API
79
79
  email:
80
80
  - girish.sonawane@gmail.com
81
81
  executables: []