google_currency 0.1.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.
- data/CHANGELOG.md +21 -0
- data/lib/money/bank/google_currency.rb +48 -0
- metadata +10 -11
- data/CHANGELOG +0 -6
data/CHANGELOG.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Google Currency 1.0.0
|
2
|
+
=====================
|
3
|
+
|
4
|
+
Features
|
5
|
+
--------
|
6
|
+
- Updated `money` requirement to `~> 3.1.0`
|
7
|
+
|
8
|
+
Google Currency 0.1.1
|
9
|
+
=====================
|
10
|
+
|
11
|
+
Features
|
12
|
+
--------
|
13
|
+
- Added #flush_rates
|
14
|
+
- Added #flush_rate
|
15
|
+
|
16
|
+
Google Currency 0.1.0
|
17
|
+
=====================
|
18
|
+
|
19
|
+
Features
|
20
|
+
--------
|
21
|
+
- Initial release
|
@@ -4,14 +4,38 @@ require 'open-uri'
|
|
4
4
|
class Money
|
5
5
|
module Bank
|
6
6
|
class GoogleCurrency < Money::Bank::VariableExchange
|
7
|
+
# @return [Hash] Stores the currently known rates.
|
7
8
|
attr_reader :rates
|
8
9
|
|
10
|
+
##
|
11
|
+
# Clears all rates stored in @rates
|
12
|
+
#
|
13
|
+
# @return [Hash] The empty @rates Hash.
|
14
|
+
#
|
15
|
+
# @example
|
16
|
+
# @bank = GoogleCurrency.new #=> <Money::Bank::GoogleCurrency...>
|
17
|
+
# @bank.get_rate(:USD, :EUR) #=> 0.776337241
|
18
|
+
# @bank.flush_rates #=> {}
|
9
19
|
def flush_rates
|
10
20
|
@mutex.synchronize{
|
11
21
|
@rates = {}
|
12
22
|
}
|
13
23
|
end
|
14
24
|
|
25
|
+
##
|
26
|
+
# Clears the specified rate stored in @rates.
|
27
|
+
#
|
28
|
+
# @param [String, Symbol, Currency] from Currency to convert from (used
|
29
|
+
# for key into @rates).
|
30
|
+
# @param [String, Symbol, Currency] to Currency to convert to (used for
|
31
|
+
# key into @rates).
|
32
|
+
#
|
33
|
+
# @return [Float] The flushed rate.
|
34
|
+
#
|
35
|
+
# @example
|
36
|
+
# @bank = GoogleCurrency.new #=> <Money::Bank::GoogleCurrency...>
|
37
|
+
# @bank.get_rate(:USD, :EUR) #=> 0.776337241
|
38
|
+
# @bank.flush_rate(:USD, :EUR) #=> 0.776337241
|
15
39
|
def flush_rate(from, to)
|
16
40
|
key = rate_key_for(from, to)
|
17
41
|
@mutex.synchronize{
|
@@ -19,12 +43,36 @@ class Money
|
|
19
43
|
}
|
20
44
|
end
|
21
45
|
|
46
|
+
##
|
47
|
+
# Returns the requested rate from @rates if it exists, otherwise calls
|
48
|
+
# +#get_google_rate+.
|
49
|
+
#
|
50
|
+
# @param [String, Symbol, Currency] from Currency to convert from
|
51
|
+
# @param [String, Symbol, Currency] to Currency to convert to
|
52
|
+
#
|
53
|
+
# @return [Float] The requested rate.
|
54
|
+
#
|
55
|
+
# @example
|
56
|
+
# @bank = GoogleCurrency.new #=> <Money::Bank::GoogleCurrency...>
|
57
|
+
# @bank.get_rate(:USD, :EUR) #=> 0.776337241
|
22
58
|
def get_rate(from, to)
|
23
59
|
@mutex.synchronize{
|
24
60
|
@rates[rate_key_for(from, to)] ||= get_google_rate(from, to)
|
25
61
|
}
|
26
62
|
end
|
27
63
|
|
64
|
+
##
|
65
|
+
# Returns the requested rate after querying Google.
|
66
|
+
#
|
67
|
+
#
|
68
|
+
# @param [String, Symbol, Currency] from Currency to convert from
|
69
|
+
# @param [String, Symbol, Currency] to Currency to convert to
|
70
|
+
#
|
71
|
+
# @return [Float] The requested rate.
|
72
|
+
#
|
73
|
+
# @example
|
74
|
+
# @bank = GoogleCurrency.new #=> <Money::Bank::GoogleCurrency...>
|
75
|
+
# @bank.get_google_rate(:USD, :EUR) #=> 0.776337241
|
28
76
|
def get_google_rate(from, to)
|
29
77
|
from = Currency.wrap(from)
|
30
78
|
to = Currency.wrap(to)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_currency
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
7
|
- 1
|
10
|
-
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Shane Emmons
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-09-14 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -56,15 +56,14 @@ dependencies:
|
|
56
56
|
requirement: &id003 !ruby/object:Gem::Requirement
|
57
57
|
none: false
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
hash:
|
61
|
+
hash: 3
|
62
62
|
segments:
|
63
63
|
- 3
|
64
64
|
- 1
|
65
65
|
- 0
|
66
|
-
|
67
|
-
version: 3.1.0.pre1
|
66
|
+
version: 3.1.0
|
68
67
|
type: :runtime
|
69
68
|
version_requirements: *id003
|
70
69
|
description: GoogleCurrency extends Money::Bank::Base and gives you access to the current Google Currency exchange rates.
|
@@ -77,12 +76,12 @@ extensions: []
|
|
77
76
|
extra_rdoc_files:
|
78
77
|
- LICENSE
|
79
78
|
- README.md
|
80
|
-
- CHANGELOG
|
79
|
+
- CHANGELOG.md
|
81
80
|
files:
|
82
81
|
- lib/money/bank/google_currency.rb
|
83
82
|
- LICENSE
|
84
83
|
- README.md
|
85
|
-
- CHANGELOG
|
84
|
+
- CHANGELOG.md
|
86
85
|
has_rdoc: true
|
87
86
|
homepage: http://rubymoney.github.com/google_currency
|
88
87
|
licenses: []
|