google_currency 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/LICENSE +20 -0
- data/README.md +29 -0
- data/lib/money/bank/google_currency.rb +31 -0
- metadata +121 -0
data/CHANGELOG
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Shane Emmons
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
Google Currency
|
2
|
+
===============
|
3
|
+
|
4
|
+
This gem extends Money::Bank::VariableExchange with Money::Bank::GoogleCurrency
|
5
|
+
and gives you access to the current Google Currency exchange rates.
|
6
|
+
|
7
|
+
Usage
|
8
|
+
-----
|
9
|
+
|
10
|
+
require 'money'
|
11
|
+
require 'money/bank/google_currency'
|
12
|
+
|
13
|
+
# set default bank to instance of GoogleCurrency
|
14
|
+
Money.default_bank = Money::Bank::GoogleCurrency.new
|
15
|
+
|
16
|
+
# create a new money object, and use the standard #exchange_to method
|
17
|
+
n = 1.to_money(:USD)
|
18
|
+
n.exchange_to(:EUR)
|
19
|
+
|
20
|
+
An `UnknownRate` will be thrown if `#exchange_to` is called with a `Currency`
|
21
|
+
that `Money` knows, but Google does not.
|
22
|
+
|
23
|
+
An `UnknownCurrency` will be thrown if `#exchange_to` is called with a
|
24
|
+
`Currency` that `Money` does not know.
|
25
|
+
|
26
|
+
Copyright
|
27
|
+
---------
|
28
|
+
|
29
|
+
Copyright (c) 2010 Shane Emmons. See {file:LICENSE} for details.
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'money'
|
2
|
+
require 'open-uri'
|
3
|
+
|
4
|
+
class Money
|
5
|
+
module Bank
|
6
|
+
class GoogleCurrency < Money::Bank::VariableExchange
|
7
|
+
attr_reader :rates
|
8
|
+
|
9
|
+
def get_rate(from, to)
|
10
|
+
@mutex.synchronize{
|
11
|
+
@rates[rate_key_for(from, to)] ||= get_google_rate(from, to)
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_google_rate(from, to)
|
16
|
+
from = Currency.wrap(from)
|
17
|
+
to = Currency.wrap(to)
|
18
|
+
|
19
|
+
data = URI.parse("http://www.google.com/ig/calculator?hl=en&q=1#{from.iso_code}%3D%3F#{to.iso_code}").read
|
20
|
+
data.gsub!(/lhs:/, ':lhs =>')
|
21
|
+
data.gsub!(/rhs:/, ':rhs =>')
|
22
|
+
data.gsub!(/error:/, ':error =>')
|
23
|
+
data.gsub!(/icc:/, ':icc =>')
|
24
|
+
data = eval(data)
|
25
|
+
|
26
|
+
raise UnknownRate unless data[:error] == '' or data[:error] == '0'
|
27
|
+
data[:rhs].split(' ')[0].to_f
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: google_currency
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Shane Emmons
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-10 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 27
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 3
|
33
|
+
- 0
|
34
|
+
version: 1.3.0
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: yard
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 27
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
- 5
|
49
|
+
- 8
|
50
|
+
version: 0.5.8
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: money
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: -916393293
|
62
|
+
segments:
|
63
|
+
- 3
|
64
|
+
- 1
|
65
|
+
- 0
|
66
|
+
- pre1
|
67
|
+
version: 3.1.0.pre1
|
68
|
+
type: :runtime
|
69
|
+
version_requirements: *id003
|
70
|
+
description: GoogleCurrency extends Money::Bank::Base and gives you access to the current Google Currency exchange rates.
|
71
|
+
email:
|
72
|
+
- semmons99+RubyMoney@gmail.com
|
73
|
+
executables: []
|
74
|
+
|
75
|
+
extensions: []
|
76
|
+
|
77
|
+
extra_rdoc_files: []
|
78
|
+
|
79
|
+
files:
|
80
|
+
- lib/money/bank/google_currency.rb
|
81
|
+
- LICENSE
|
82
|
+
- README.md
|
83
|
+
- CHANGELOG
|
84
|
+
has_rdoc: true
|
85
|
+
homepage: http://rubymoney.github.com/google_currency
|
86
|
+
licenses: []
|
87
|
+
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
hash: 3
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
version: "0"
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
hash: 21
|
108
|
+
segments:
|
109
|
+
- 1
|
110
|
+
- 3
|
111
|
+
- 7
|
112
|
+
version: 1.3.7
|
113
|
+
requirements: []
|
114
|
+
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 1.3.7
|
117
|
+
signing_key:
|
118
|
+
specification_version: 3
|
119
|
+
summary: Access the Google Currency exchange rate data.
|
120
|
+
test_files: []
|
121
|
+
|