fixer 0.2.1 → 0.3.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/.rspec +1 -1
- data/.rvmrc +0 -1
- data/Gemfile.lock +10 -14
- data/LICENSE +1 -1
- data/README.md +11 -0
- data/Rakefile +0 -1
- data/fixer.gemspec +2 -4
- data/lib/fixer.rb +0 -2
- data/lib/fixer/version.rb +1 -2
- data/spec/fixer_spec.rb +3 -1
- data/spec/spec_helper.rb +1 -3
- metadata +11 -28
- data/README.markdown +0 -30
- data/lib/fixer/cache.rb +0 -52
- data/spec/fixer/cache_spec.rb +0 -80
data/.rspec
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
--color
|
data/.rvmrc
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fixer (0.
|
4
|
+
fixer (0.3.0)
|
5
5
|
nokogiri (~> 1.4.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -9,17 +9,14 @@ GEM
|
|
9
9
|
specs:
|
10
10
|
diff-lcs (1.1.2)
|
11
11
|
nokogiri (1.4.3.1)
|
12
|
-
|
13
|
-
|
14
|
-
rspec-
|
15
|
-
rspec-
|
16
|
-
|
17
|
-
rspec-
|
18
|
-
|
19
|
-
|
20
|
-
rspec-mocks (2.0.0.rc)
|
21
|
-
rspec-core (= 2.0.0.rc)
|
22
|
-
rspec-expectations (= 2.0.0.rc)
|
12
|
+
rspec (2.1.0)
|
13
|
+
rspec-core (~> 2.1.0)
|
14
|
+
rspec-expectations (~> 2.1.0)
|
15
|
+
rspec-mocks (~> 2.1.0)
|
16
|
+
rspec-core (2.1.0)
|
17
|
+
rspec-expectations (2.1.0)
|
18
|
+
diff-lcs (~> 1.1.2)
|
19
|
+
rspec-mocks (2.1.0)
|
23
20
|
|
24
21
|
PLATFORMS
|
25
22
|
ruby
|
@@ -27,5 +24,4 @@ PLATFORMS
|
|
27
24
|
DEPENDENCIES
|
28
25
|
fixer!
|
29
26
|
nokogiri (~> 1.4.0)
|
30
|
-
|
31
|
-
rspec (= 2.0.0.rc)
|
27
|
+
rspec (~> 2.1.0)
|
data/LICENSE
CHANGED
data/README.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
Fixer
|
2
|
+
====
|
3
|
+
|
4
|
+
Fixer wraps the current and historical [foreign exchange rate feeds](http://www.ecb.europa.eu/stats/exchange/eurofxref/html/index.en.html) of the European Central Bank.
|
5
|
+
|
6
|
+
Usage
|
7
|
+
-----
|
8
|
+
|
9
|
+
Fixer.daily
|
10
|
+
Fixer.historical_90
|
11
|
+
Fixer.historical
|
data/Rakefile
CHANGED
data/fixer.gemspec
CHANGED
@@ -10,14 +10,12 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.email = ["code@papercavalier.com"]
|
11
11
|
s.homepage = "http://fixer.heroku.com"
|
12
12
|
s.summary = "A Ruby wrapper to the European Central Bank exchange rate feeds"
|
13
|
-
s.description = "Fixer is a Ruby wrapper to the current and historical foreign exchange or FX rate feeds
|
13
|
+
s.description = "Fixer is a Ruby wrapper to the current and historical foreign exchange or FX rate feeds of the European Central Bank."
|
14
14
|
|
15
15
|
s.rubyforge_project = "fixer"
|
16
16
|
|
17
17
|
s.add_dependency("nokogiri", ["~> 1.4.0"])
|
18
|
-
|
19
|
-
s.add_development_dependency("rake")
|
20
|
-
s.add_development_dependency("rspec", ["= 2.0.0.rc"])
|
18
|
+
s.add_development_dependency("rspec", ["~> 2.1.0"])
|
21
19
|
|
22
20
|
s.files = `git ls-files`.split("\n")
|
23
21
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
data/lib/fixer.rb
CHANGED
data/lib/fixer/version.rb
CHANGED
data/spec/fixer_spec.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
require 'spec_helper'
|
3
2
|
|
4
3
|
describe Fixer do
|
5
4
|
it "downloads daily rates" do
|
6
5
|
rates = Fixer.daily
|
6
|
+
|
7
7
|
rates.size.should eql 1
|
8
8
|
rates.first.should have_key :date
|
9
9
|
rates.first.should have_key :rates
|
@@ -11,6 +11,7 @@ describe Fixer do
|
|
11
11
|
|
12
12
|
it "downloads 90-day historical" do
|
13
13
|
rates = Fixer.historical_90
|
14
|
+
|
14
15
|
# We should have more than 50 working days in a three-month period
|
15
16
|
rates.size.should > 50
|
16
17
|
rates.each do |rate|
|
@@ -21,6 +22,7 @@ describe Fixer do
|
|
21
22
|
|
22
23
|
it "downloads historical" do
|
23
24
|
rates = Fixer.historical
|
25
|
+
|
24
26
|
# We should have a lot of working days in history
|
25
27
|
rates.size.should > 1000
|
26
28
|
rates.each do |rate|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 0.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Hakan Ensari
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-12-03 00:00:00 +00:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -32,36 +32,22 @@ dependencies:
|
|
32
32
|
version: 1.4.0
|
33
33
|
type: :runtime
|
34
34
|
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: rake
|
37
|
-
prerelease: false
|
38
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
|
-
requirements:
|
41
|
-
- - ">="
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
segments:
|
44
|
-
- 0
|
45
|
-
version: "0"
|
46
|
-
type: :development
|
47
|
-
version_requirements: *id002
|
48
35
|
- !ruby/object:Gem::Dependency
|
49
36
|
name: rspec
|
50
37
|
prerelease: false
|
51
|
-
requirement: &
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
52
39
|
none: false
|
53
40
|
requirements:
|
54
|
-
- -
|
41
|
+
- - ~>
|
55
42
|
- !ruby/object:Gem::Version
|
56
43
|
segments:
|
57
44
|
- 2
|
45
|
+
- 1
|
58
46
|
- 0
|
59
|
-
|
60
|
-
- rc
|
61
|
-
version: 2.0.0.rc
|
47
|
+
version: 2.1.0
|
62
48
|
type: :development
|
63
|
-
version_requirements: *
|
64
|
-
description: Fixer is a Ruby wrapper to the current and historical foreign exchange or FX rate feeds
|
49
|
+
version_requirements: *id002
|
50
|
+
description: Fixer is a Ruby wrapper to the current and historical foreign exchange or FX rate feeds of the European Central Bank.
|
65
51
|
email:
|
66
52
|
- code@papercavalier.com
|
67
53
|
executables: []
|
@@ -77,13 +63,11 @@ files:
|
|
77
63
|
- Gemfile
|
78
64
|
- Gemfile.lock
|
79
65
|
- LICENSE
|
80
|
-
- README.
|
66
|
+
- README.md
|
81
67
|
- Rakefile
|
82
68
|
- fixer.gemspec
|
83
69
|
- lib/fixer.rb
|
84
|
-
- lib/fixer/cache.rb
|
85
70
|
- lib/fixer/version.rb
|
86
|
-
- spec/fixer/cache_spec.rb
|
87
71
|
- spec/fixer_spec.rb
|
88
72
|
- spec/spec_helper.rb
|
89
73
|
has_rdoc: true
|
@@ -119,6 +103,5 @@ signing_key:
|
|
119
103
|
specification_version: 3
|
120
104
|
summary: A Ruby wrapper to the European Central Bank exchange rate feeds
|
121
105
|
test_files:
|
122
|
-
- spec/fixer/cache_spec.rb
|
123
106
|
- spec/fixer_spec.rb
|
124
107
|
- spec/spec_helper.rb
|
data/README.markdown
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
Fixer
|
2
|
-
====
|
3
|
-
|
4
|
-
Fixer is a Ruby wrapper to the [current and historical foreign exchange rate feeds provided by the European Central Bank](http://www.ecb.europa.eu/stats/exchange/eurofxref/html/index.en.html).
|
5
|
-
|
6
|
-
I am also throwing in a *minimal* cache. Use if it suits you or implement your own.
|
7
|
-
|
8
|
-
Bonus: Use the Money gem.
|
9
|
-
|
10
|
-
Usage
|
11
|
-
-----
|
12
|
-
|
13
|
-
# Download the daily rates.
|
14
|
-
Fixer.daily
|
15
|
-
|
16
|
-
# Download the 90-day historical rates.
|
17
|
-
Fixer.historical_90
|
18
|
-
|
19
|
-
# Download all historical rates.
|
20
|
-
Fixer.historical
|
21
|
-
|
22
|
-
# Use the built-in cache.
|
23
|
-
cache = Fixer::Cache
|
24
|
-
cache.to_usd
|
25
|
-
=> 1.397
|
26
|
-
cache.base = "EUR"
|
27
|
-
cache.to_eur
|
28
|
-
=> 0.7158
|
29
|
-
|
30
|
-
# It doesn't get any simpler than this.
|
data/lib/fixer/cache.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
module Fixer
|
3
|
-
class Cache
|
4
|
-
class << self
|
5
|
-
def base
|
6
|
-
@base || "EUR"
|
7
|
-
end
|
8
|
-
|
9
|
-
def base=(name)
|
10
|
-
@base = name
|
11
|
-
end
|
12
|
-
|
13
|
-
def expire
|
14
|
-
@rates = nil
|
15
|
-
end
|
16
|
-
|
17
|
-
def method_missing(sym, *args, &block)
|
18
|
-
if sym.to_s =~ /^to_(.*)$/
|
19
|
-
counter = $1.upcase
|
20
|
-
var_name = "@#{base}_#{counter}".to_sym
|
21
|
-
rate = instance_variable_get(var_name)
|
22
|
-
return rate unless rate.nil?
|
23
|
-
|
24
|
-
rate = quote(counter) / quote(base)
|
25
|
-
rate = (rate * 10000).round.to_f / 10000
|
26
|
-
instance_variable_set(var_name, rate)
|
27
|
-
rate
|
28
|
-
else
|
29
|
-
super
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def rates
|
36
|
-
begin
|
37
|
-
@rates ||= Fixer.daily.first[:rates].push({ :currency => "EUR", :rate => "1.0" })
|
38
|
-
rescue
|
39
|
-
raise Error, "Cache not valid"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def quote(counter)
|
44
|
-
rate = rates.detect { |rate| rate[:currency] == counter }
|
45
|
-
raise(Error, "#{counter} not a valid currency") if rate.nil?
|
46
|
-
rate[:rate].to_f
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
class Error < StandardError; end
|
52
|
-
end
|
data/spec/fixer/cache_spec.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
module Fixer
|
5
|
-
describe Cache do
|
6
|
-
let(:mock_rates) do
|
7
|
-
[
|
8
|
-
{ :currency=>"USD", :rate=>"1.3856" },
|
9
|
-
{ :currency=>"JPY", :rate=>"114.98" },
|
10
|
-
{ :currency=>"GBP", :rate=>"0.87260" },
|
11
|
-
{ :currency=>"CAD", :rate=>"1.4018" },
|
12
|
-
{ :currency=>"EUR", :rate=>"1.0" }
|
13
|
-
]
|
14
|
-
end
|
15
|
-
|
16
|
-
let(:cache) do
|
17
|
-
cache = Fixer::Cache
|
18
|
-
cache.base = "EUR"
|
19
|
-
cache.expire
|
20
|
-
cache
|
21
|
-
end
|
22
|
-
|
23
|
-
it "sets base currency" do
|
24
|
-
cache.base = "USD"
|
25
|
-
cache.base.should eql "USD"
|
26
|
-
end
|
27
|
-
|
28
|
-
it "quotes" do
|
29
|
-
cache.instance_variable_set(:@rates, mock_rates)
|
30
|
-
cache.send(:quote, "USD").should eql 1.3856
|
31
|
-
end
|
32
|
-
|
33
|
-
it "caches" do
|
34
|
-
cache.instance_variable_set(:@rates, "foo")
|
35
|
-
cache.send(:rates).should eql "foo"
|
36
|
-
end
|
37
|
-
|
38
|
-
it "seeds cache" do
|
39
|
-
cache.send(:rates).detect { |rate| rate[:currency] == "USD" }[:rate].should_not be_nil
|
40
|
-
end
|
41
|
-
|
42
|
-
it "expires cache" do
|
43
|
-
cache.instance_variable_set(:@rates, "foo")
|
44
|
-
cache.expire
|
45
|
-
cache.instance_variable_get(:@rates).should be_nil
|
46
|
-
end
|
47
|
-
|
48
|
-
it "raises an error if cache not valid" do
|
49
|
-
Fixer.stub!(:daily).and_return("foo")
|
50
|
-
lambda { cache.send(:rates) }.should raise_error Fixer::Error, "Cache not valid"
|
51
|
-
end
|
52
|
-
|
53
|
-
it "returns an exchange rate" do
|
54
|
-
cache.instance_variable_set(:@rates, mock_rates)
|
55
|
-
cache.to_eur.should eql 1.0
|
56
|
-
cache.to_usd.should eql 1.3856
|
57
|
-
|
58
|
-
cache.base = "GBP"
|
59
|
-
cache.to_gbp.should eql 1.0
|
60
|
-
cache.to_usd.should eql 1.5879
|
61
|
-
end
|
62
|
-
|
63
|
-
it "caches requested exchange rates" do
|
64
|
-
cache.instance_variable_set(:@rates, mock_rates)
|
65
|
-
cache.to_usd
|
66
|
-
cache.instance_variable_get(:@EUR_USD).should eql 1.3856
|
67
|
-
end
|
68
|
-
|
69
|
-
it "raises an error if counter currency not valid" do
|
70
|
-
cache.instance_variable_set(:@rates, mock_rates)
|
71
|
-
lambda { cache.to_foo }.should raise_error Fixer::Error, "FOO not a valid currency"
|
72
|
-
end
|
73
|
-
|
74
|
-
it "raises an error if base currency not valid" do
|
75
|
-
cache.instance_variable_set(:@rates, mock_rates)
|
76
|
-
cache.base = "BAR"
|
77
|
-
lambda { cache.to_usd }.should raise_error Fixer::Error, "BAR not a valid currency"
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|