eu_central_bank 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -28,8 +28,11 @@ With the gem, you do not need to manually add exchange rates. Calling update_rat
28
28
 
29
29
  # exchange 100 CAD to USD
30
30
  # API is the same as the money gem
31
- eu_bank.exchange(100, "CAD", "USD") # 124
32
- Money.us_dollar(100).exchange_to("CAD") # Money.ca_dollar(124)
31
+ eu_bank.exchange(100, "CAD", "USD") # Money.new(80, "USD")
32
+ Money.us_dollar(100).exchange_to("CAD") # Money.new(124, "CAD")
33
+
34
+ # using the new exchange_with method
35
+ eu_bank.exchange_with(Money.new(100, "CAD"), "USD") # Money.new(80, "USD")
33
36
 
34
37
  For performance reasons, you may prefer to read from a file instead. Furthermore, ECB publishes their rates daily. It makes sense to save the rates in a file to read from.
35
38
 
@@ -40,7 +43,11 @@ For performance reasons, you may prefer to read from a file instead. Furthermore
40
43
  eu_bank.update_rates("/some/file/location/exchange_rates.xml")
41
44
 
42
45
  # exchange 100 CAD to USD as usual
43
- eu_bank.exchange(100, "CAD", "USD") # 124
46
+ eu_bank.exchange_with(Money.new(100, "CAD"), "USD") # Money.new(80, "USD")
47
+
48
+ == Deprecation
49
+
50
+ Note that the *exchange* method will be deprecated in Money version 3.2.0. eu_central_bank will follow suite and deprecate the method in version 0.2.0
44
51
 
45
52
  == Note on Patches/Pull Requests
46
53
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{eu_central_bank}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Wong Liang Zan"]
12
- s.date = %q{2010-04-21}
12
+ s.date = %q{2010-07-17}
13
13
  s.description = %q{This gem reads exchange rates from the european central bank website. It uses it to calculates exchange rates. It is compatible with the money gem}
14
14
  s.email = %q{zan@liangzan.net}
15
15
  s.extra_rdoc_files = [
@@ -34,18 +34,18 @@ Gem::Specification.new do |s|
34
34
  s.homepage = %q{http://github.com/liangzan/eu_central_bank}
35
35
  s.rdoc_options = ["--charset=UTF-8"]
36
36
  s.require_paths = ["lib"]
37
- s.rubygems_version = %q{1.3.6}
37
+ s.rubygems_version = %q{1.3.7}
38
38
  s.summary = %q{Calculates exchange rates based on rates from european central bank. Money gem compatible.}
39
39
  s.test_files = [
40
- "spec/eu_central_bank_spec.rb",
41
- "spec/spec_helper.rb"
40
+ "spec/spec_helper.rb",
41
+ "spec/eu_central_bank_spec.rb"
42
42
  ]
43
43
 
44
44
  if s.respond_to? :specification_version then
45
45
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
46
  s.specification_version = 3
47
47
 
48
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
48
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
49
  s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
50
50
  s.add_development_dependency(%q<rr>, [">= 0.10.11"])
51
51
  s.add_development_dependency(%q<shoulda>, [">= 2.10.3"])
@@ -28,13 +28,18 @@ class EuCentralBank < Money::VariableExchangeBank
28
28
  end
29
29
 
30
30
  def exchange(cents, from_currency, to_currency)
31
- rate = get_rate(from_currency, to_currency)
32
- if !rate
33
- from_base_rate = get_rate("EUR", from_currency)
31
+ warn '[DEPRECIATION] `exchange` will be removed in money v3.2.0 and eu_central_bank v0.2.0, use #exchange_with instead'
32
+ exchange_with(Money.new(cents, from_currency), to_currency)
33
+ end
34
+
35
+ def exchange_with(from, to_currency)
36
+ rate = get_rate(from.currency, to_currency)
37
+ unless rate
38
+ from_base_rate = get_rate("EUR", from.currency)
34
39
  to_base_rate = get_rate("EUR", to_currency)
35
40
  rate = to_base_rate / from_base_rate
36
41
  end
37
- (cents * rate).floor
42
+ Money.new((from.cents * rate).floor, to_currency)
38
43
  end
39
44
 
40
45
  protected
@@ -1,4 +1,5 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'yaml'
2
3
 
3
4
  describe "EuCentralBank" do
4
5
  before(:each) do
@@ -38,11 +39,19 @@ describe "EuCentralBank" do
38
39
  end
39
40
  end
40
41
 
41
- it "should return the correct exchange rates" do
42
+ it "should return the correct exchange rates using exchange" do
42
43
  EXCHANGE_RATES = YAML.load_file(@yml_cache_path)
43
44
  @bank.update_rates(@cache_path)
44
45
  EuCentralBank::CURRENCIES.each do |currency|
45
- @bank.exchange(100, "EUR", currency).should == (EXCHANGE_RATES["currencies"][currency].to_f * 100).floor
46
+ @bank.exchange(100, "EUR", currency).cents.should == (EXCHANGE_RATES["currencies"][currency].to_f * 100).floor
47
+ end
48
+ end
49
+
50
+ it "should return the correct exchange rates using exchange_with" do
51
+ EXCHANGE_RATES = YAML.load_file(@yml_cache_path)
52
+ @bank.update_rates(@cache_path)
53
+ EuCentralBank::CURRENCIES.each do |currency|
54
+ @bank.exchange_with(Money.new(100, "EUR"), currency).cents.should == (EXCHANGE_RATES["currencies"][currency].to_f * 100).floor
46
55
  end
47
56
  end
48
57
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eu_central_bank
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 25
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 1
8
- - 0
9
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Wong Liang Zan
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-04-21 00:00:00 +08:00
18
+ date: 2010-07-17 00:00:00 +08:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: rspec
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 27
27
30
  segments:
28
31
  - 1
29
32
  - 3
@@ -35,9 +38,11 @@ dependencies:
35
38
  name: rr
36
39
  prerelease: false
37
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
38
42
  requirements:
39
43
  - - ">="
40
44
  - !ruby/object:Gem::Version
45
+ hash: 33
41
46
  segments:
42
47
  - 0
43
48
  - 10
@@ -49,9 +54,11 @@ dependencies:
49
54
  name: shoulda
50
55
  prerelease: false
51
56
  requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
52
58
  requirements:
53
59
  - - ">="
54
60
  - !ruby/object:Gem::Version
61
+ hash: 33
55
62
  segments:
56
63
  - 2
57
64
  - 10
@@ -63,9 +70,11 @@ dependencies:
63
70
  name: nokogiri
64
71
  prerelease: false
65
72
  requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
66
74
  requirements:
67
75
  - - ">="
68
76
  - !ruby/object:Gem::Version
77
+ hash: 5
69
78
  segments:
70
79
  - 1
71
80
  - 4
@@ -77,9 +86,11 @@ dependencies:
77
86
  name: money
78
87
  prerelease: false
79
88
  requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
80
90
  requirements:
81
91
  - - ">="
82
92
  - !ruby/object:Gem::Version
93
+ hash: 3
83
94
  segments:
84
95
  - 2
85
96
  - 3
@@ -120,26 +131,30 @@ rdoc_options:
120
131
  require_paths:
121
132
  - lib
122
133
  required_ruby_version: !ruby/object:Gem::Requirement
134
+ none: false
123
135
  requirements:
124
136
  - - ">="
125
137
  - !ruby/object:Gem::Version
138
+ hash: 3
126
139
  segments:
127
140
  - 0
128
141
  version: "0"
129
142
  required_rubygems_version: !ruby/object:Gem::Requirement
143
+ none: false
130
144
  requirements:
131
145
  - - ">="
132
146
  - !ruby/object:Gem::Version
147
+ hash: 3
133
148
  segments:
134
149
  - 0
135
150
  version: "0"
136
151
  requirements: []
137
152
 
138
153
  rubyforge_project:
139
- rubygems_version: 1.3.6
154
+ rubygems_version: 1.3.7
140
155
  signing_key:
141
156
  specification_version: 3
142
157
  summary: Calculates exchange rates based on rates from european central bank. Money gem compatible.
143
158
  test_files:
144
- - spec/eu_central_bank_spec.rb
145
159
  - spec/spec_helper.rb
160
+ - spec/eu_central_bank_spec.rb