momm 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/bin/momm +4 -2
- data/lib/momm.rb +3 -6
- data/lib/momm/calculator.rb +15 -4
- data/lib/momm/memcached.rb +2 -2
- data/lib/momm/storage.rb +2 -2
- data/lib/momm/version.rb +1 -1
- data/spec/momm/calculator_spec.rb +2 -6
- data/spec/momm/memcached_spec.rb +2 -0
- data/spec/momm/momm_spec.rb +12 -0
- data/spec/momm/redis_store_spec.rb +2 -0
- data/spec/momm/version_spec.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88f614087dabe0ac7ecef7529fd568c0c1ddb058
|
4
|
+
data.tar.gz: 03a1106a8ecaf7d43d0589b2ebdb6b0fcb79ee46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6d66f452241aeac2a0ebf7003fd42880a228b47423a99f7edb8a6a8c6fcf926a3dd9ea04844d1ec958273804cf4b12c398e2381a2d32cc0854e1e4b1973c116
|
7
|
+
data.tar.gz: 12575b5a233a3c8a088a9a7b0c5f649237e1c9a7453023b4f5568b0b4bf0324b2bdb8ca3521895506c80477ec9a69df898024dd5180bb555e2dfe639bad22082
|
data/README.md
CHANGED
@@ -59,6 +59,7 @@ After the gem is installed, momm provide you a command line tool. The storage en
|
|
59
59
|
```
|
60
60
|
$ momm rate GBP CNY # Exchange rate by default is today.
|
61
61
|
$ momm exchange 100 GBP USD 2014-3-1 # Exchange rate at 2013-3-1
|
62
|
+
$ momm update # Fetch feeds from remote and update the storage
|
62
63
|
```
|
63
64
|
|
64
65
|
#### Ruby
|
@@ -75,6 +76,8 @@ After the gem is installed, momm provide you a command line tool. The storage en
|
|
75
76
|
Momm.exchange 100, 'GBP', 'USD', date: Date.today
|
76
77
|
Momm.exchange_from_gbp_to_usd 100
|
77
78
|
Momm.exchange_from_gbp_to_usd 100, date: "2014-3-4"
|
79
|
+
|
80
|
+
Momm.update! # Fetching the feeds from remote. Only do that if you find any abnormal.
|
78
81
|
```
|
79
82
|
|
80
83
|
#### Configuration
|
data/bin/momm
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH << File.dirname(__FILE__) + "/../lib" if $0 == __FILE__
|
|
4
4
|
require 'optparse'
|
5
5
|
require 'momm'
|
6
6
|
|
7
|
-
OPERATIONS = %w{rate exchange}
|
7
|
+
OPERATIONS = %w{rate exchange update}
|
8
8
|
|
9
9
|
option_parser = OptionParser.new do |opts|
|
10
10
|
opts.banner = Momm::BANNER
|
@@ -15,7 +15,7 @@ Supported commands:
|
|
15
15
|
|
16
16
|
rate [country_code] [country_code] [YYYY-MM-DD] Display rate!
|
17
17
|
exchange [money] [country_code] [country_code] [YYYY-MM-DD] Exchange for you!
|
18
|
-
|
18
|
+
update Fetch feeds from Remote!
|
19
19
|
Examples:
|
20
20
|
momm exchange 20 GBP CNY Convert the between currencies
|
21
21
|
momm rate GBP CNY Simply display the rate
|
@@ -57,6 +57,8 @@ if OPERATIONS.include?(op)
|
|
57
57
|
end
|
58
58
|
|
59
59
|
puts Momm.exchange money, from, to, date: date
|
60
|
+
when "update"
|
61
|
+
puts Momm.update!
|
60
62
|
end
|
61
63
|
|
62
64
|
rescue ArgumentError => ex
|
data/lib/momm.rb
CHANGED
@@ -54,17 +54,14 @@ module Momm
|
|
54
54
|
# delegate the exchange, :currencies, exchange_rate,
|
55
55
|
# as well as meta programmed methods to module level
|
56
56
|
delegate [:currencies, :exchange, :exchange_rate,
|
57
|
-
:method_missing, :respond_to
|
57
|
+
:method_missing, :respond_to?, :update! ] => :calculator
|
58
58
|
|
59
59
|
private
|
60
60
|
|
61
61
|
# Delegate the calculator
|
62
62
|
def calculator
|
63
|
-
@calculator
|
64
|
-
|
65
|
-
else
|
66
|
-
Calculator.new
|
67
|
-
end
|
63
|
+
@calculator = Calculator.new(
|
64
|
+
(storage || Memcached.new), (feed || Feeds::ECB.instance))
|
68
65
|
end
|
69
66
|
end
|
70
67
|
|
data/lib/momm/calculator.rb
CHANGED
@@ -16,14 +16,25 @@ module Momm
|
|
16
16
|
|
17
17
|
attr_reader :storage, :feed
|
18
18
|
|
19
|
-
# delegate the client and
|
20
|
-
delegate [:client, :
|
19
|
+
# delegate the client and set_rate method from storage
|
20
|
+
delegate [:client, :set_rate] => :storage
|
21
21
|
|
22
22
|
# delegate the currencies method from feed
|
23
23
|
delegate :currencies => :feed
|
24
24
|
|
25
|
-
# delegate
|
25
|
+
# delegate methods with different naming for overriding
|
26
26
|
def_delegator :storage, :get_rate, :get_rate_origin
|
27
|
+
def_delegator :storage, :update, :origin_update
|
28
|
+
|
29
|
+
|
30
|
+
# Update the feeds. In most case, you do not need to call this,
|
31
|
+
# because Momm will update the feeds everytime she find something missing ;)
|
32
|
+
# == Returns
|
33
|
+
# nil
|
34
|
+
#
|
35
|
+
def update!
|
36
|
+
origin_update(feed.currency_rates)
|
37
|
+
end
|
27
38
|
|
28
39
|
# Exchange Rate
|
29
40
|
#
|
@@ -101,7 +112,7 @@ module Momm
|
|
101
112
|
res = get_rate_origin(from, date)
|
102
113
|
return res if res != 0 && res
|
103
114
|
|
104
|
-
update
|
115
|
+
update!
|
105
116
|
get_rate_origin(from, date)
|
106
117
|
end
|
107
118
|
|
data/lib/momm/memcached.rb
CHANGED
data/lib/momm/storage.rb
CHANGED
@@ -54,13 +54,13 @@ module Momm
|
|
54
54
|
# An array looks like [{date: Date.now, currency: :CNY, rate: 1.23} ...]
|
55
55
|
#
|
56
56
|
# == Returns
|
57
|
-
#
|
57
|
+
# "OK"
|
58
58
|
#
|
59
59
|
def update(data)
|
60
60
|
data.each do |d|
|
61
61
|
set_rate d[:currency], d[:rate], d[:date]
|
62
62
|
end
|
63
|
-
|
63
|
+
"OK"
|
64
64
|
end
|
65
65
|
|
66
66
|
NotImplementedError = Class.new(StandardError)
|
data/lib/momm/version.rb
CHANGED
@@ -9,10 +9,6 @@ describe Momm::Calculator do
|
|
9
9
|
calc.should respond_to :client
|
10
10
|
end
|
11
11
|
|
12
|
-
it 'should response to update' do
|
13
|
-
calc.should respond_to :update
|
14
|
-
end
|
15
|
-
|
16
12
|
it 'should response to set_rate' do
|
17
13
|
calc.should respond_to :set_rate
|
18
14
|
end
|
@@ -41,8 +37,8 @@ describe Momm::Calculator do
|
|
41
37
|
calc.should respond_to :client
|
42
38
|
end
|
43
39
|
|
44
|
-
it 'should response to update' do
|
45
|
-
calc.should respond_to :update
|
40
|
+
it 'should response to update!' do
|
41
|
+
calc.should respond_to :update!
|
46
42
|
end
|
47
43
|
|
48
44
|
it 'should response to set_rate' do
|
data/spec/momm/memcached_spec.rb
CHANGED
data/spec/momm/momm_spec.rb
CHANGED
@@ -17,5 +17,17 @@ describe Momm do
|
|
17
17
|
it "should respond to exchange_rate_from_gbp_to_usd" do
|
18
18
|
Momm.should respond_to :exchange_rate_from_gbp_to_usd
|
19
19
|
end
|
20
|
+
|
21
|
+
it "should respond to update!" do
|
22
|
+
Momm.should respond_to :update!
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context ".store" do
|
27
|
+
it "should be successfully switch to redis store halfway" do
|
28
|
+
Momm.store :redis_store
|
29
|
+
Momm.send(:calculator).storage.client.should be_a(Redis::Namespace)
|
30
|
+
Momm.store :memcached
|
31
|
+
end
|
20
32
|
end
|
21
33
|
end
|
data/spec/momm/version_spec.rb
CHANGED