spot-rate 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -4
- data/lib/spot-rate.rb +13 -5
- data/lib/spot_rate/version.rb +1 -1
- data/spec/spot_rate_spec.rb +13 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -25,9 +25,9 @@ currency converters are registered:
|
|
25
25
|
require 'spot-rate'
|
26
26
|
|
27
27
|
puts Time.now
|
28
|
-
puts SpotRate.new(:from_currency => 'USD', :to_currency => 'JPY').spot_rate
|
29
28
|
# => 2013-05-01 18:34:09 -0700
|
30
|
-
|
29
|
+
puts SpotRate.new(:from_currency => 'USD', :to_currency => 'CAD').spot_rate
|
30
|
+
# => 1.01689986
|
31
31
|
```
|
32
32
|
|
33
33
|
If you'd like to register your own currency converter, use the
|
@@ -48,11 +48,11 @@ class MyRandomCurrencyConverter
|
|
48
48
|
end
|
49
49
|
|
50
50
|
SpotRate.register_currency_converter(:random_converter, MyRandomCurrencyConverter)
|
51
|
-
spot_rate = SpotRate.new(:from_currency => 'USD', :to_currency => '
|
51
|
+
spot_rate = SpotRate.new(:from_currency => 'USD', :to_currency => 'CAD')
|
52
52
|
puts spot_rate.use(:random_converter).spot_rate
|
53
53
|
# => 0.5363022464905228
|
54
54
|
puts spot_rate.spot_rate # will go back to using the pre-packaged default Google converter
|
55
|
-
# =>
|
55
|
+
# => 1.01689986
|
56
56
|
```
|
57
57
|
|
58
58
|
## Contributing
|
data/lib/spot-rate.rb
CHANGED
@@ -10,18 +10,26 @@ class SpotRate
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.register_currency_converter converter_key, converter_class
|
13
|
-
self.available_converters[converter_key] = converter_class
|
13
|
+
self.available_converters[converter_key.to_sym] = converter_class
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
16
|
+
def self.[](hash)
|
17
|
+
raise ArgumentError unless hash.size <= 2
|
18
|
+
|
19
|
+
new(from_currency: hash.keys.first, to_currency: hash.values.first)
|
20
|
+
.use(hash[:use] || hash[:using] || :default)
|
21
|
+
.spot_rate
|
22
|
+
end
|
23
|
+
|
24
|
+
def initialize(config = {})
|
17
25
|
@from_currency = config[:from_currency]
|
18
26
|
@to_currency = config[:to_currency]
|
19
27
|
end
|
20
28
|
|
21
|
-
def use
|
29
|
+
def use(requested_converter_key)
|
22
30
|
self.class
|
23
|
-
.available_converters[requested_converter_key]
|
24
|
-
|
31
|
+
.available_converters[requested_converter_key.to_sym]
|
32
|
+
.new(@from_currency, @to_currency)
|
25
33
|
end
|
26
34
|
|
27
35
|
def spot_rate
|
data/lib/spot_rate/version.rb
CHANGED
data/spec/spot_rate_spec.rb
CHANGED
@@ -12,6 +12,19 @@ class SomeCurrencyConverter
|
|
12
12
|
end
|
13
13
|
|
14
14
|
describe SpotRate do
|
15
|
+
describe "[]" do
|
16
|
+
it "returns the requested spot rate using the requested converter" do
|
17
|
+
SpotRate.register_currency_converter :some_currency_converter, SomeCurrencyConverter
|
18
|
+
expect(SpotRate['this' => 'that', use: :some_currency_converter]).to eq 'this that'
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns the requested spot rate using the default converter if nothing specified" do
|
22
|
+
stub_converter = stub(:spot_rate => 'this that')
|
23
|
+
SpotRate::GoogleCurrencyConverter.stub(:new).and_return(stub_converter)
|
24
|
+
expect(SpotRate['this' => 'that']).to eq 'this that'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
15
28
|
describe ".register_currency_converter" do
|
16
29
|
it "adds the converter to the list of available currency converters" do
|
17
30
|
expect(SpotRate.available_converters).to_not include SomeCurrencyConverter
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spot-rate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: net-sftp
|