currencies 0.3.0 → 0.4.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.
@@ -0,0 +1,7 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
6
+ .rake_tasks~
7
+ .bundle/
@@ -10,21 +10,32 @@ Currencies is hosted on GemCutter, so simply run the following:
10
10
 
11
11
  gem sources -a http://gemcutter.org
12
12
  sudo gem install currencies
13
-
13
+
14
+ Or you can install via bundler Gemfile:
15
+
16
+ gem 'currencies'
17
+
18
+ Or you can install via bundler Gemfile with using only ISO4217::Currency (no Currency class):
19
+
20
+ gem 'currencies', :require => 'iso4217'
21
+
14
22
  Basic Usage
15
23
  -----------
16
24
 
25
+ Note that Currency class still exist by default.
26
+ (is inherited from ISO4217::Currency to keep backward compatibility).
27
+
17
28
  There are two ways to get a currency object. The first is to simply make it.
18
29
 
19
- Currency.new('USD', :name => 'Dollars', :symbol => '$', :exchange_rate => 1)
30
+ ISO4217::Currency.new('USD', :name => 'Dollars', :symbol => '$', :exchange_rate => 1)
20
31
 
21
32
  Or you can lookup a currency by its ISO 4217 code using the *from_code* method.
22
33
 
23
- Currency.from_code('USD')
34
+ ISO4217::Currency.from_code('USD')
24
35
 
25
36
  Once you have a Currency instance you can get basic information about it.
26
37
 
27
- currency = Currency.from_code('USD')
38
+ currency = ISO4217::Currency.from_code('USD')
28
39
  currency.code #=> "USD"
29
40
  currency.name #=> "Dollars"
30
41
  currency.symbol #=> "$"
@@ -36,12 +47,12 @@ Adding Currencies
36
47
 
37
48
  Currencies keeps an internal list of currencies for use in the ExchangeBank and to be looked up with the *from_code* method. By default this list contains all the currencies in the ISO 4217 standard. A custom currency can be added using the *add* class method.
38
49
 
39
- shiny_button = Currency.new('SBTTN', :name => 'Buttons', :symbol => '☼', :exchange_rate => 1000)
40
- Currency.add(shiny_button)
50
+ shiny_button = ISO4217::Currency.new('SBTTN', :name => 'Buttons', :symbol => '☼', :exchange_rate => 1000)
51
+ ISO4217::Currency.add(shiny_button)
41
52
 
42
53
  To do a massive addition of currencies you can load a yaml file using the *load_file* class method.
43
54
 
44
- Currency.load_file('custom_currency.yaml')
55
+ ISO4217::Currency.load_file('custom_currency.yaml')
45
56
 
46
57
  And the yaml file should look like ...
47
58
 
@@ -54,11 +65,11 @@ Defaults
54
65
 
55
66
  You can set the base currency by using the *base_currency* class method. This defaults to 'USD'.
56
67
 
57
- Currency.base_currency => 'GBP'
68
+ ISO4217::Currency.base_currency => 'GBP'
58
69
 
59
70
  The exchange rate is either set manually or if nil looked up on Yahoo Finance and cached. If you want to disable looking up the currency set the *import_exchange_rates* class method to false.
60
71
 
61
- Currency.import_exchange_rates = false
72
+ ISO4217::Currency.import_exchange_rates = false
62
73
 
63
74
 
64
75
  Money Gem
@@ -66,7 +77,7 @@ Money Gem
66
77
 
67
78
  To use with the money gem you just set the default bank to the currencies bank.
68
79
 
69
- Money.default_bank = Currency::ExchangeBank.new
80
+ Money.default_bank = ISO4217::Currency::ExchangeBank.new
70
81
 
71
82
  The Currencies ExchangeBank works the same as the one in the money gem except that if an exchange rate isn't set by default it uses what is set in the currencies gem.
72
83
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
@@ -1,48 +1,51 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{currencies}
8
- s.version = "0.3.0"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["hexorx"]
12
- s.date = %q{2011-01-10}
12
+ s.date = %q{2011-02-07}
13
13
  s.description = %q{If you are tracking any kind of assets the currencies gem is for you. It contains every currency in the ISO 4217 standard and allows you to add your own as well. So if you decide to take sparkly buttons as a form of payment you can use currencies to display the shiny button unicode symbol ☼ (disclaimer: ☼ may not look like a shiny button to everyone.) when used with something like the money gem. Speaking of the money gem, currencies gives you an ExchangeBank that the money gem can use to convert from one currency to another. There are plans to have ExchangeRate provider plugin system. Right now the rates are either set manually or pulled from Yahoo Finance.}
14
14
  s.email = %q{hexorx@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.markdown"
17
+ "README.markdown"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
- ".rvmrc",
22
- "Gemfile",
23
- "Gemfile.lock",
24
- "LICENSE",
25
- "README.markdown",
26
- "Rakefile",
27
- "VERSION",
28
- "currencies.gemspec",
29
- "lib/currencies.rb",
30
- "lib/currencies/currency.rb",
31
- "lib/currencies/exchange_bank.rb",
32
- "lib/currencies/extentions.rb",
33
- "lib/data/iso4217.yaml",
34
- "spec/currency_spec.rb",
35
- "spec/exchange_bank_spec.rb",
36
- "spec/spec_helper.rb"
21
+ ".gitignore",
22
+ ".rvmrc",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE",
26
+ "README.markdown",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "currencies.gemspec",
30
+ "lib/currencies.rb",
31
+ "lib/currencies/currency.rb",
32
+ "lib/currencies/exchange_bank.rb",
33
+ "lib/currencies/extentions.rb",
34
+ "lib/data/iso4217.yaml",
35
+ "lib/iso4217.rb",
36
+ "spec/currency_spec.rb",
37
+ "spec/exchange_bank_spec.rb",
38
+ "spec/spec_helper.rb"
37
39
  ]
38
40
  s.homepage = %q{http://github.com/hexorx/currencies}
41
+ s.rdoc_options = ["--charset=UTF-8"]
39
42
  s.require_paths = ["lib"]
40
43
  s.rubygems_version = %q{1.3.7}
41
44
  s.summary = %q{Simple gem for working with currencies. It is extracted from the countries gem and contains all the currency information in the ISO 4217 standard.}
42
45
  s.test_files = [
43
46
  "spec/currency_spec.rb",
44
- "spec/exchange_bank_spec.rb",
45
- "spec/spec_helper.rb"
47
+ "spec/exchange_bank_spec.rb",
48
+ "spec/spec_helper.rb"
46
49
  ]
47
50
 
48
51
  if s.respond_to? :specification_version then
@@ -50,19 +53,13 @@ Gem::Specification.new do |s|
50
53
  s.specification_version = 3
51
54
 
52
55
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
- s.add_runtime_dependency(%q<jeweler>, ["= 1.4.0"])
54
- s.add_runtime_dependency(%q<rspec>, ["= 1.3.1"])
55
56
  s.add_development_dependency(%q<rspec>, [">= 0"])
56
57
  s.add_development_dependency(%q<yard>, [">= 0"])
57
58
  else
58
- s.add_dependency(%q<jeweler>, ["= 1.4.0"])
59
- s.add_dependency(%q<rspec>, ["= 1.3.1"])
60
59
  s.add_dependency(%q<rspec>, [">= 0"])
61
60
  s.add_dependency(%q<yard>, [">= 0"])
62
61
  end
63
62
  else
64
- s.add_dependency(%q<jeweler>, ["= 1.4.0"])
65
- s.add_dependency(%q<rspec>, ["= 1.3.1"])
66
63
  s.add_dependency(%q<rspec>, [">= 0"])
67
64
  s.add_dependency(%q<yard>, [">= 0"])
68
65
  end
@@ -1,8 +1,6 @@
1
1
  $LOAD_PATH << File.expand_path(File.dirname(__FILE__))
2
2
 
3
- require 'YAML' unless defined?(YAML)
4
- require 'net/http' unless defined?(Net::HTTP)
3
+ require 'iso4217'
5
4
 
6
- require 'currencies/extentions'
7
- require 'currencies/currency'
8
- require 'currencies/exchange_bank'
5
+ class Currency < ISO4217::Currency
6
+ end
@@ -1,4 +1,7 @@
1
- class Currency
1
+ module ISO4217
2
+ end
3
+
4
+ class ISO4217::Currency
2
5
  class << self
3
6
  attr_accessor :currencies
4
7
  attr_accessor :base_currency
@@ -12,7 +15,7 @@ class Currency
12
15
  @code = iso_code.to_s.upcase
13
16
  @name = opts['name']
14
17
  @symbol = opts['symbol']
15
- @exchange_currency = opts['exchange_currency'] || Currency.base_currency
18
+ @exchange_currency = opts['exchange_currency'] || self.class.base_currency
16
19
  @exchange_rate = opts['exchange_rate'].to_f if opts['exchange_rate']
17
20
  end
18
21
 
@@ -21,14 +24,14 @@ class Currency
21
24
  end
22
25
 
23
26
  def exchange_rate
24
- @exchange_rate = nil unless @exchange_currency == Currency.base_currency
27
+ @exchange_rate = nil unless @exchange_currency == self.class.base_currency
25
28
  @exchange_rate ||= load_exchange_rate
26
29
  end
27
30
 
28
31
  def load_exchange_rate
29
- @exchange_currency = Currency.base_currency
32
+ @exchange_currency = self.class.base_currency
30
33
  return 1.0 if @code == @exchange_currency
31
- if Currency.import_exchange_rates
34
+ if self.class.import_exchange_rates
32
35
  http = Net::HTTP.new('download.finance.yahoo.com', 80)
33
36
  response = http.get("/d/quotes.csv?e=.csv&f=sl1d1t1&s=#{@code}#{@exchange_currency}=X")
34
37
  rate = response.body.split(',')[1]
@@ -49,7 +52,7 @@ class Currency
49
52
  end
50
53
 
51
54
  def self.major_currencies_selection(currencies)
52
- currencies.select { |code, currency| Currency.major_codes.include?(code) }.first
55
+ currencies.select { |code, currency| self.major_codes.include?(code) }.first
53
56
  end
54
57
 
55
58
  def self.best_from_currencies(currencies)
@@ -1,6 +1,6 @@
1
1
  require 'thread'
2
2
 
3
- class Currency
3
+ class ISO4217::Currency
4
4
  class ExchangeBank
5
5
  def self.instance
6
6
  @@singleton
@@ -32,8 +32,8 @@ class Currency
32
32
  if rate
33
33
  (cents * rate).floor
34
34
  else
35
- from_currency = Currency.from_code(from_currency)
36
- to_currency = Currency.from_code(to_currency)
35
+ from_currency = ISO4217::Currency.from_code(from_currency)
36
+ to_currency = ISO4217::Currency.from_code(to_currency)
37
37
 
38
38
  if from_currency && to_currency && from_currency.exchange_rate && to_currency.exchange_rate && (from_currency.exchange_currency == to_currency.exchange_currency)
39
39
  ((cents * from_currency.exchange_rate) / to_currency.exchange_rate).floor
@@ -45,4 +45,4 @@ class Currency
45
45
 
46
46
  @@singleton = ExchangeBank.new
47
47
  end
48
- end
48
+ end
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH << File.expand_path(File.dirname(__FILE__))
2
+
3
+ require 'YAML' unless defined?(YAML)
4
+ require 'net/http' unless defined?(Net::HTTP)
5
+
6
+ require 'currencies/extentions'
7
+ require 'currencies/currency'
8
+ require 'currencies/exchange_bank'
@@ -1,9 +1,9 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- describe Currency do
3
+ describe ISO4217::Currency do
4
4
  before(:all) do
5
- @usd = Currency.from_code(:USD)
6
- @gbp = Currency.from_code(:GBP)
5
+ @usd = ISO4217::Currency.from_code(:USD)
6
+ @gbp = ISO4217::Currency.from_code(:GBP)
7
7
  end
8
8
 
9
9
  it 'should return code' do
@@ -35,32 +35,32 @@ describe Currency do
35
35
 
36
36
  describe 'from_code' do
37
37
  it 'should return new Currency instance when passed iso4217 currency code' do
38
- Currency.from_code('USD').should be_a(Currency)
38
+ ISO4217::Currency.from_code('USD').should be_a(ISO4217::Currency)
39
39
  end
40
40
 
41
41
  it 'should return a currency with the same code' do
42
- Currency.from_code('USD').code.should == 'USD'
43
- Currency.from_code('GBP').code.should == 'GBP'
42
+ ISO4217::Currency.from_code('USD').code.should == 'USD'
43
+ ISO4217::Currency.from_code('GBP').code.should == 'GBP'
44
44
  end
45
45
 
46
46
  it 'should accept symbol' do
47
- Currency.from_code(:USD).code.should == 'USD'
48
- Currency.from_code(:GBP).code.should == 'GBP'
47
+ ISO4217::Currency.from_code(:USD).code.should == 'USD'
48
+ ISO4217::Currency.from_code(:GBP).code.should == 'GBP'
49
49
  end
50
50
 
51
51
  it 'should work with lower case' do
52
- Currency.from_code('usd').code.should == 'USD'
53
- Currency.from_code('gbp').code.should == 'GBP'
52
+ ISO4217::Currency.from_code('usd').code.should == 'USD'
53
+ ISO4217::Currency.from_code('gbp').code.should == 'GBP'
54
54
  end
55
55
  end
56
56
 
57
57
  describe 'exchange_rate' do
58
58
  it 'should return a float' do
59
- Currency.from_code('GBP').exchange_rate.should be_a(Float)
59
+ ISO4217::Currency.from_code('GBP').exchange_rate.should be_a(Float)
60
60
  end
61
61
 
62
62
  it 'should have an exchange rate of 1.0 for the base currency' do
63
- Currency.from_code(Currency.base_currency).exchange_rate.should == 1.0
63
+ ISO4217::Currency.from_code(ISO4217::Currency.base_currency).exchange_rate.should == 1.0
64
64
  end
65
65
  end
66
66
 
@@ -71,7 +71,7 @@ describe Currency do
71
71
 
72
72
  context "with default settings" do
73
73
  subject do
74
- Currency.major_currencies_selection(currencies)
74
+ ISO4217::Currency.major_currencies_selection(currencies)
75
75
  end
76
76
 
77
77
  it { should == usd }
@@ -79,8 +79,8 @@ describe Currency do
79
79
 
80
80
  context "with changed major currency to AUD" do
81
81
  subject do
82
- Currency.major_codes = [ "AUD" ]
83
- Currency.major_currencies_selection(currencies)
82
+ ISO4217::Currency.major_codes = [ "AUD" ]
83
+ ISO4217::Currency.major_currencies_selection(currencies)
84
84
  end
85
85
 
86
86
  it { should == aud }
@@ -93,13 +93,13 @@ describe Currency do
93
93
  let(:aud) { mock }
94
94
 
95
95
  context "when given currencies is nil" do
96
- subject { Currency.best_from_currencies(nil) }
96
+ subject { ISO4217::Currency.best_from_currencies(nil) }
97
97
 
98
98
  it { should be_nil }
99
99
  end
100
100
 
101
101
  context "when given currencies is empty array" do
102
- subject { Currency.best_from_currencies([]) }
102
+ subject { ISO4217::Currency.best_from_currencies([]) }
103
103
 
104
104
  it { should be_nil }
105
105
  end
@@ -107,8 +107,8 @@ describe Currency do
107
107
  context "when major currency exist within currencies" do
108
108
  let(:valid_currencies) { mock(:nil? => false, :empty? => false) }
109
109
  subject do
110
- Currency.stub!(:major_currencies_selection => [mock, usd])
111
- Currency.best_from_currencies(valid_currencies)
110
+ ISO4217::Currency.stub!(:major_currencies_selection => [mock, usd])
111
+ ISO4217::Currency.best_from_currencies(valid_currencies)
112
112
  end
113
113
 
114
114
  it { should == usd }
@@ -117,8 +117,8 @@ describe Currency do
117
117
  context "when major currency does not exist within currencies" do
118
118
  let(:valid_currencies) { [ [mock, pln], [mock, aud] ] }
119
119
  subject do
120
- Currency.stub!(:major_currencies_selection => nil)
121
- Currency.best_from_currencies(valid_currencies)
120
+ ISO4217::Currency.stub!(:major_currencies_selection => nil)
121
+ ISO4217::Currency.best_from_currencies(valid_currencies)
122
122
  end
123
123
 
124
124
  it { should == pln }
@@ -136,8 +136,8 @@ describe Currency do
136
136
  let(:currencies) { euro + dollars }
137
137
 
138
138
  subject do
139
- Currency.stub!(:currencies => currencies)
140
- Currency.list_from_name("Dollars")
139
+ ISO4217::Currency.stub!(:currencies => currencies)
140
+ ISO4217::Currency.list_from_name("Dollars")
141
141
  end
142
142
 
143
143
  it { should == dollars }
@@ -154,8 +154,8 @@ describe Currency do
154
154
  let(:currencies) { euro + dollars }
155
155
 
156
156
  subject do
157
- Currency.stub!(:currencies => currencies)
158
- Currency.list_from_symbol("$")
157
+ ISO4217::Currency.stub!(:currencies => currencies)
158
+ ISO4217::Currency.list_from_symbol("$")
159
159
  end
160
160
 
161
161
  it { should == dollars }
@@ -166,30 +166,30 @@ describe Currency do
166
166
  let(:list_from_name) { mock }
167
167
  describe "behavior" do
168
168
  before do
169
- Currency.stub!(
169
+ ISO4217::Currency.stub!(
170
170
  :best_from_currencies => nil,
171
171
  :list_from_name => list_from_name
172
172
  )
173
173
  end
174
- after { Currency.best_from_name(name) }
174
+ after { ISO4217::Currency.best_from_name(name) }
175
175
 
176
176
  it "should select best from list of currencies with given name" do
177
- Currency.should_receive(:best_from_currencies).with(list_from_name)
177
+ ISO4217::Currency.should_receive(:best_from_currencies).with(list_from_name)
178
178
  end
179
179
 
180
180
  it "should select list of currencies with given name" do
181
- Currency.should_receive(:list_from_name).with(name).and_return(list_from_name)
181
+ ISO4217::Currency.should_receive(:list_from_name).with(name).and_return(list_from_name)
182
182
  end
183
183
  end
184
184
 
185
185
  describe "returns" do
186
186
  let(:best_from_currencies) { mock }
187
187
  subject do
188
- Currency.stub!(
188
+ ISO4217::Currency.stub!(
189
189
  :best_from_currencies => best_from_currencies,
190
190
  :list_from_name => list_from_name
191
191
  )
192
- Currency.best_from_name(name)
192
+ ISO4217::Currency.best_from_name(name)
193
193
  end
194
194
 
195
195
  it { should == best_from_currencies }
@@ -201,30 +201,30 @@ describe Currency do
201
201
  let(:list_from_symbol) { mock }
202
202
  describe "behavior" do
203
203
  before do
204
- Currency.stub!(
204
+ ISO4217::Currency.stub!(
205
205
  :best_from_currencies => nil,
206
206
  :list_from_symbol => list_from_symbol
207
207
  )
208
208
  end
209
- after { Currency.best_from_symbol(symbol) }
209
+ after { ISO4217::Currency.best_from_symbol(symbol) }
210
210
 
211
211
  it "should select best from list of currencies with given symbol" do
212
- Currency.should_receive(:best_from_currencies).with(list_from_symbol)
212
+ ISO4217::Currency.should_receive(:best_from_currencies).with(list_from_symbol)
213
213
  end
214
214
 
215
215
  it "should select list of currencies with given symbol" do
216
- Currency.should_receive(:list_from_symbol).with(symbol).and_return(list_from_symbol)
216
+ ISO4217::Currency.should_receive(:list_from_symbol).with(symbol).and_return(list_from_symbol)
217
217
  end
218
218
  end
219
219
 
220
220
  describe "returns" do
221
221
  let(:best_from_currencies) { mock }
222
222
  subject do
223
- Currency.stub!(
223
+ ISO4217::Currency.stub!(
224
224
  :best_from_currencies => best_from_currencies,
225
225
  :list_from_symbol => list_from_symbol
226
226
  )
227
- Currency.best_from_symbol(symbol)
227
+ ISO4217::Currency.best_from_symbol(symbol)
228
228
  end
229
229
 
230
230
  it { should == best_from_currencies }
@@ -236,21 +236,21 @@ describe Currency do
236
236
  let(:string) { mock(:nil? => false, :empty? => false) }
237
237
 
238
238
  context "when string not given" do
239
- subject { Currency.best_guess(nil) }
239
+ subject { ISO4217::Currency.best_guess(nil) }
240
240
 
241
241
  it { should be_nil }
242
242
  end
243
243
 
244
244
  context "when given empty string" do
245
- subject { Currency.best_guess("") }
245
+ subject { ISO4217::Currency.best_guess("") }
246
246
 
247
247
  it { should be_nil }
248
248
  end
249
249
 
250
250
  context "when code equal to string exist" do
251
251
  subject do
252
- Currency.stub!(:from_code).with(string).and_return(eur)
253
- Currency.best_guess(string)
252
+ ISO4217::Currency.stub!(:from_code).with(string).and_return(eur)
253
+ ISO4217::Currency.best_guess(string)
254
254
  end
255
255
 
256
256
  it { should == eur }
@@ -258,9 +258,9 @@ describe Currency do
258
258
 
259
259
  context "when best symbol equal to string exist" do
260
260
  subject do
261
- Currency.stub!(:from_code).with(string).and_return(nil)
262
- Currency.stub!(:best_from_symbol).with(string).and_return(eur)
263
- Currency.best_guess(string)
261
+ ISO4217::Currency.stub!(:from_code).with(string).and_return(nil)
262
+ ISO4217::Currency.stub!(:best_from_symbol).with(string).and_return(eur)
263
+ ISO4217::Currency.best_guess(string)
264
264
  end
265
265
 
266
266
  it { should == eur }
@@ -268,10 +268,10 @@ describe Currency do
268
268
 
269
269
  context "when best name equal to string exist" do
270
270
  subject do
271
- Currency.stub!(:from_code).with(string).and_return(nil)
272
- Currency.stub!(:best_from_symbol).with(string).and_return(nil)
273
- Currency.stub!(:best_from_name).with(string).and_return(eur)
274
- Currency.best_guess(string)
271
+ ISO4217::Currency.stub!(:from_code).with(string).and_return(nil)
272
+ ISO4217::Currency.stub!(:best_from_symbol).with(string).and_return(nil)
273
+ ISO4217::Currency.stub!(:best_from_name).with(string).and_return(eur)
274
+ ISO4217::Currency.best_guess(string)
275
275
  end
276
276
 
277
277
  it { should == eur }
@@ -279,10 +279,10 @@ describe Currency do
279
279
 
280
280
  context "when string not exist in any form" do
281
281
  subject do
282
- Currency.stub!(:from_code).with(string).and_return(nil)
283
- Currency.stub!(:best_from_symbol).with(string).and_return(nil)
284
- Currency.stub!(:best_from_name).with(string).and_return(nil)
285
- Currency.best_guess(string)
282
+ ISO4217::Currency.stub!(:from_code).with(string).and_return(nil)
283
+ ISO4217::Currency.stub!(:best_from_symbol).with(string).and_return(nil)
284
+ ISO4217::Currency.stub!(:best_from_name).with(string).and_return(nil)
285
+ ISO4217::Currency.best_guess(string)
286
286
  end
287
287
 
288
288
  it { should be_nil }
@@ -290,10 +290,10 @@ describe Currency do
290
290
 
291
291
  describe "behavior" do
292
292
  it "should run methods in proper order" do
293
- Currency.should_receive(:from_code).ordered.with("string").and_return(nil)
294
- Currency.should_receive(:best_from_symbol).ordered.with("string").and_return(nil)
295
- Currency.should_receive(:best_from_name).ordered.with("string").and_return(nil)
296
- Currency.best_guess("string")
293
+ ISO4217::Currency.should_receive(:from_code).ordered.with("string").and_return(nil)
294
+ ISO4217::Currency.should_receive(:best_from_symbol).ordered.with("string").and_return(nil)
295
+ ISO4217::Currency.should_receive(:best_from_name).ordered.with("string").and_return(nil)
296
+ ISO4217::Currency.best_guess("string")
297
297
  end
298
298
  end
299
299
  end
@@ -305,8 +305,8 @@ describe Currency do
305
305
 
306
306
  context "when there is best guess" do
307
307
  subject do
308
- Currency.stub!(:best_guess).with(string).and_return(best_guess)
309
- Currency.code_from_best_guess(string)
308
+ ISO4217::Currency.stub!(:best_guess).with(string).and_return(best_guess)
309
+ ISO4217::Currency.code_from_best_guess(string)
310
310
  end
311
311
 
312
312
  it { should == code }
@@ -316,19 +316,19 @@ describe Currency do
316
316
  let(:best_guess) { mock(:try => nil) }
317
317
 
318
318
  subject do
319
- Currency.stub!(:best_guess).with(string).and_return(best_guess)
320
- Currency.code_from_best_guess(string)
319
+ ISO4217::Currency.stub!(:best_guess).with(string).and_return(best_guess)
320
+ ISO4217::Currency.code_from_best_guess(string)
321
321
  end
322
322
 
323
323
  it { should be_nil }
324
324
  end
325
325
 
326
326
  describe "behavior" do
327
- before { Currency.stub!(:best_guess).with(string).and_return(best_guess) }
328
- after { Currency.code_from_best_guess(string) }
327
+ before { ISO4217::Currency.stub!(:best_guess).with(string).and_return(best_guess) }
328
+ after { ISO4217::Currency.code_from_best_guess(string) }
329
329
 
330
330
  it "should call .best_guess" do
331
- Currency.should_receive(:best_guess).with(string).and_return(best_guess)
331
+ ISO4217::Currency.should_receive(:best_guess).with(string).and_return(best_guess)
332
332
  end
333
333
 
334
334
  it "should call #code on best guessed" do
@@ -337,4 +337,28 @@ describe Currency do
337
337
  end
338
338
  end
339
339
 
340
+ describe "Currency class" do
341
+ context "when loaded via 'iso4217' existance" do
342
+ subject { defined?(Currency) }
343
+
344
+ it { should be_false }
345
+ end
346
+
347
+ context "when loaded via 'currencies'" do
348
+ before { require 'currencies' }
349
+
350
+ describe "existance" do
351
+ subject { defined?(Currency) }
352
+
353
+ it { should be_true }
354
+ end
355
+
356
+ describe "superclass" do
357
+ subject { Currency.superclass }
358
+
359
+ it { should == ISO4217::Currency }
360
+ end
361
+ end
362
+ end
363
+
340
364
  end
@@ -1,8 +1,8 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- describe Currency::ExchangeBank do
3
+ describe ISO4217::Currency::ExchangeBank do
4
4
  before :each do
5
- @bank = Currency::ExchangeBank.new
5
+ @bank = ISO4217::Currency::ExchangeBank.new
6
6
  end
7
7
 
8
8
  it "returns the previously specified conversion rate" do
@@ -46,4 +46,4 @@ describe Currency::ExchangeBank do
46
46
  block = lambda { @bank.exchange(10, "USD", "BUTTON") }
47
47
  block.should raise_error(Money::UnknownRate)
48
48
  end
49
- end
49
+ end
@@ -1,6 +1,6 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'currencies'
3
+ require 'iso4217'
4
4
  require 'spec'
5
5
  require 'spec/autorun'
6
6
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: currencies
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
8
+ - 4
9
9
  - 0
10
- version: 0.3.0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - hexorx
@@ -15,46 +15,13 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-10 00:00:00 -07:00
18
+ date: 2011-02-07 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- type: :runtime
23
- prerelease: false
24
- name: jeweler
25
- version_requirements: &id001 !ruby/object:Gem::Requirement
26
- none: false
27
- requirements:
28
- - - "="
29
- - !ruby/object:Gem::Version
30
- hash: 7
31
- segments:
32
- - 1
33
- - 4
34
- - 0
35
- version: 1.4.0
36
- requirement: *id001
37
- - !ruby/object:Gem::Dependency
38
- type: :runtime
39
- prerelease: false
40
22
  name: rspec
41
- version_requirements: &id002 !ruby/object:Gem::Requirement
42
- none: false
43
- requirements:
44
- - - "="
45
- - !ruby/object:Gem::Version
46
- hash: 25
47
- segments:
48
- - 1
49
- - 3
50
- - 1
51
- version: 1.3.1
52
- requirement: *id002
53
- - !ruby/object:Gem::Dependency
54
- type: :development
55
23
  prerelease: false
56
- name: rspec
57
- version_requirements: &id003 !ruby/object:Gem::Requirement
24
+ requirement: &id001 !ruby/object:Gem::Requirement
58
25
  none: false
59
26
  requirements:
60
27
  - - ">="
@@ -63,12 +30,12 @@ dependencies:
63
30
  segments:
64
31
  - 0
65
32
  version: "0"
66
- requirement: *id003
67
- - !ruby/object:Gem::Dependency
68
33
  type: :development
69
- prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
70
36
  name: yard
71
- version_requirements: &id004 !ruby/object:Gem::Requirement
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
72
39
  none: false
73
40
  requirements:
74
41
  - - ">="
@@ -77,7 +44,8 @@ dependencies:
77
44
  segments:
78
45
  - 0
79
46
  version: "0"
80
- requirement: *id004
47
+ type: :development
48
+ version_requirements: *id002
81
49
  description: "If you are tracking any kind of assets the currencies gem is for you. It contains every currency in the ISO 4217 standard and allows you to add your own as well. So if you decide to take sparkly buttons as a form of payment you can use currencies to display the shiny button unicode symbol \xE2\x98\xBC (disclaimer: \xE2\x98\xBC may not look like a shiny button to everyone.) when used with something like the money gem. Speaking of the money gem, currencies gives you an ExchangeBank that the money gem can use to convert from one currency to another. There are plans to have ExchangeRate provider plugin system. Right now the rates are either set manually or pulled from Yahoo Finance."
82
50
  email: hexorx@gmail.com
83
51
  executables: []
@@ -89,6 +57,7 @@ extra_rdoc_files:
89
57
  - README.markdown
90
58
  files:
91
59
  - .document
60
+ - .gitignore
92
61
  - .rvmrc
93
62
  - Gemfile
94
63
  - Gemfile.lock
@@ -102,6 +71,7 @@ files:
102
71
  - lib/currencies/exchange_bank.rb
103
72
  - lib/currencies/extentions.rb
104
73
  - lib/data/iso4217.yaml
74
+ - lib/iso4217.rb
105
75
  - spec/currency_spec.rb
106
76
  - spec/exchange_bank_spec.rb
107
77
  - spec/spec_helper.rb
@@ -110,8 +80,8 @@ homepage: http://github.com/hexorx/currencies
110
80
  licenses: []
111
81
 
112
82
  post_install_message:
113
- rdoc_options: []
114
-
83
+ rdoc_options:
84
+ - --charset=UTF-8
115
85
  require_paths:
116
86
  - lib
117
87
  required_ruby_version: !ruby/object:Gem::Requirement