xurrency 001 → 002
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/.gemified +3 -3
- data/History.txt +7 -1
- data/lib/xurrency.rb +13 -9
- data/spec/xurrency_spec.rb +29 -1
- metadata +2 -2
data/.gemified
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
---
|
2
2
|
:summary: ruby-xurrency is a wrapper library for API xurrency(http://xurrency.com/api).
|
3
3
|
:email: keita.yamaguchi@gmail.com
|
4
|
-
:has_rdoc: true
|
5
4
|
:name: xurrency
|
5
|
+
:has_rdoc: true
|
6
6
|
:homepage: http://rubyforge.org/projects/xurrency/
|
7
|
-
:version: "
|
7
|
+
:version: "002"
|
8
|
+
:rubyforge_project: xurrency
|
8
9
|
:dependencies:
|
9
10
|
- soap4r
|
10
|
-
:rubyforge_project: xurrency
|
11
11
|
:author: Keita Yamaguchi
|
data/History.txt
CHANGED
data/lib/xurrency.rb
CHANGED
@@ -5,7 +5,7 @@ require "singleton"
|
|
5
5
|
require "delegate"
|
6
6
|
|
7
7
|
class Xurrency
|
8
|
-
VERSION = "
|
8
|
+
VERSION = "002"
|
9
9
|
|
10
10
|
# Soap client.
|
11
11
|
class Client < Delegator #:nodoc:
|
@@ -89,13 +89,6 @@ class Xurrency
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
-
# Updates the result value.
|
93
|
-
def update(name, *args)
|
94
|
-
raise ArgumentError, name unless @cache.has_key?(name)
|
95
|
-
@cache[name][args] = nil
|
96
|
-
__send__(name, *args)
|
97
|
-
end
|
98
|
-
|
99
92
|
# Calculates the value without quering getValue.
|
100
93
|
def value(amount, base, target)
|
101
94
|
values(base)[target] * amount
|
@@ -106,11 +99,22 @@ class Xurrency
|
|
106
99
|
# Memoize some queries.
|
107
100
|
def memoize(name)
|
108
101
|
@cache[name] = {}
|
109
|
-
(class << self; self; end)
|
102
|
+
klass = (class << self; self; end)
|
103
|
+
klass.__send__(:define_method, name) do |*args|
|
110
104
|
return @cache[name][args] if @cache[name].has_key?(args)
|
111
105
|
@cache[name][args] = Request.send(name, *args)
|
112
106
|
@cache[name][args][:timestamp] = Time.now if name.to_s =~ /values/
|
113
107
|
return @cache[name][args]
|
114
108
|
end
|
109
|
+
klass.__send__(:define_method, "update_#{name}") do |*args|
|
110
|
+
@cache[name].delete(args)
|
111
|
+
__send__(name, *args)
|
112
|
+
end
|
113
|
+
klass.__send__(:define_method, "#{name}_cached?") do |*args|
|
114
|
+
@cache[name].has_key?(args)
|
115
|
+
end
|
116
|
+
klass.__send__(:define_method, "clear_#{name}") do |*args|
|
117
|
+
@cache[name].delete(args)
|
118
|
+
end
|
115
119
|
end
|
116
120
|
end
|
data/spec/xurrency_spec.rb
CHANGED
@@ -16,6 +16,34 @@ describe "Xurrency" do
|
|
16
16
|
res = $xu.zone("jpy")
|
17
17
|
res.should == "Japan"
|
18
18
|
res.__id__.should == $xu.zone("jpy").__id__
|
19
|
-
res.__id__.should.not == $xu.
|
19
|
+
res.__id__.should.not == $xu.update_zone("jpy").__id__
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should know weather cached or not" do
|
23
|
+
$xu.zone_cached?("cny").should.be.false
|
24
|
+
$xu.zone("cny")
|
25
|
+
$xu.zone_cached?("cny").should.be.true
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should clear cache" do
|
29
|
+
$xu.zone("usd")
|
30
|
+
$xu.zone_cached?("usd").should.be.true
|
31
|
+
$xu.clear_zone("usd")
|
32
|
+
$xu.zone_cached?("usd").should.be.false
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should respond methods" do
|
36
|
+
methods = []
|
37
|
+
list = [ "currency_name",
|
38
|
+
"zone",
|
39
|
+
"url",
|
40
|
+
"currencies",
|
41
|
+
"values",
|
42
|
+
"values_inverse" ]
|
43
|
+
methods += list
|
44
|
+
methods += list.map {|name| "update_#{name}" }
|
45
|
+
methods += list.map {|name| "clear_#{name}" }
|
46
|
+
methods += list.map {|name| "#{name}_cached?" }
|
47
|
+
methods.each {|name| $xu.methods.should.include? name }
|
20
48
|
end
|
21
49
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xurrency
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "
|
4
|
+
version: "002"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keita Yamaguchi
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-04-
|
12
|
+
date: 2008-04-20 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|