redis-bank 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/redis-bank.rb +6 -4
- metadata +5 -5
data/lib/redis-bank.rb
CHANGED
@@ -5,6 +5,8 @@ class Money
|
|
5
5
|
# Thrown when an unknown rate format is requested.
|
6
6
|
class UnknownRateFormat < StandardError; end
|
7
7
|
|
8
|
+
KEY='redis_bank_exchange_rates'
|
9
|
+
|
8
10
|
# Class for aiding in exchanging money between different currencies. By
|
9
11
|
# default, the +Money+ class uses an object of this class (accessible
|
10
12
|
# through +Money#bank+) for performing currency exchanges.
|
@@ -31,7 +33,7 @@ class Money
|
|
31
33
|
|
32
34
|
# hash of exchange rates
|
33
35
|
def rates
|
34
|
-
@redis_client.
|
36
|
+
@redis_client.hgetall KEY
|
35
37
|
end
|
36
38
|
|
37
39
|
# Exchanges the given +Money+ object to a new +Money+ object in
|
@@ -118,7 +120,7 @@ class Money
|
|
118
120
|
# bank.set_rate("USD", "CAD", 1.24515)
|
119
121
|
# bank.set_rate("CAD", "USD", 0.803115)
|
120
122
|
def set_rate(from, to, rate)
|
121
|
-
@redis_client
|
123
|
+
@redis_client.hset KEY, rate_key_for(from, to), rate
|
122
124
|
end
|
123
125
|
|
124
126
|
# Retrieve the rate for the given currencies. Uses +Mutex+ to synchronize
|
@@ -137,7 +139,7 @@ class Money
|
|
137
139
|
# bank.get_rate("USD", "CAD") #=> 1.24515
|
138
140
|
# bank.get_rate("CAD", "USD") #=> 0.803115
|
139
141
|
def get_rate(from, to)
|
140
|
-
@redis_client
|
142
|
+
@redis_client.hget KEY, rate_key_for(from, to)
|
141
143
|
end
|
142
144
|
|
143
145
|
# Return the rate hashkey for the given currencies.
|
@@ -150,7 +152,7 @@ class Money
|
|
150
152
|
# @example
|
151
153
|
# rate_key_for("USD", "CAD") #=> "exchange_rate_usd_to_cad"
|
152
154
|
def rate_key_for(from, to)
|
153
|
-
"
|
155
|
+
"#{Currency.wrap(from).iso_code}_to_#{Currency.wrap(to).iso_code}".downcase
|
154
156
|
end
|
155
157
|
end
|
156
158
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-bank
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Cameron Walsh
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-06-
|
18
|
+
date: 2012-06-20 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: money
|
@@ -115,7 +115,7 @@ dependencies:
|
|
115
115
|
version: "0"
|
116
116
|
type: :development
|
117
117
|
version_requirements: *id007
|
118
|
-
description: Redis-backed Bank for the Money gem based on the
|
118
|
+
description: Redis-backed Bank for the Money gem based on the VariableExchange Bank
|
119
119
|
email: cameron.walsh@gmail.com
|
120
120
|
executables: []
|
121
121
|
|