exchange 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,6 +20,11 @@ describe "Exchange::Money" do
20
20
  subject.value.should == 40
21
21
  subject.currency.should == :usd
22
22
  end
23
+ it "should initialize with a number and a country code" do
24
+ from_country_code = Exchange::Money.new(50, :de)
25
+ from_country_code.value.should == 50
26
+ from_country_code.currency.should == :eur
27
+ end
23
28
  describe "initializing with a block" do
24
29
  it "should be possible" do
25
30
  currency = Exchange::Money.new(40) do |c|
@@ -33,14 +38,27 @@ describe "Exchange::Money" do
33
38
  end
34
39
  end
35
40
  describe "to" do
36
- it "should be able to convert itself to other currencies" do
37
- mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 3)
38
- subject.to(:chf).value.round(2).should == 36.5
39
- subject.to(:chf).currency.should == :chf
40
- subject.to(:chf).should be_kind_of Exchange::Money
41
+ context "with a currency" do
42
+ it "should be able to convert itself to other currencies" do
43
+ mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 3)
44
+ subject.to(:chf).value.round(2).should == 36.5
45
+ subject.to(:chf).currency.should == :chf
46
+ subject.to(:chf).should be_kind_of Exchange::Money
47
+ end
48
+ end
49
+ context "with a country argument" do
50
+ it "should be able to convert itself to the currency of the country" do
51
+ mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 3)
52
+ subject.to(:ch).value.round(2).should == 36.5
53
+ subject.to(:ch).currency.should == :chf
54
+ subject.to(:ch).should be_kind_of Exchange::Money
55
+ end
41
56
  end
42
57
  end
43
58
  describe "operations" do
59
+ after(:each) do
60
+ Exchange.configuration.implicit_conversions = true
61
+ end
44
62
  describe "+ other" do
45
63
  it "should be able to add an integer" do
46
64
  (subject + 40).value.should == 80
@@ -62,13 +80,11 @@ describe "Exchange::Money" do
62
80
  it "should raise when currencies get mixed and the configuration does not allow it" do
63
81
  Exchange.configuration.implicit_conversions = false
64
82
  lambda { subject + Exchange::Money.new(30, :chf) }.should raise_error(Exchange::ImplicitConversionError)
65
- Exchange.configuration.implicit_conversions = true
66
83
  end
67
84
  it "should not raise when currencies get mixed and the configuration does not allow if the other currency is the same" do
68
85
  Exchange.configuration.implicit_conversions = false
69
86
  mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
70
87
  lambda { subject + Exchange::Money.new(30, :usd) }.should_not raise_error
71
- Exchange.configuration.implicit_conversions = true
72
88
  end
73
89
  context "modifying the base value" do
74
90
  before(:each) do
@@ -107,6 +123,9 @@ describe "Exchange::Money" do
107
123
  end
108
124
  end
109
125
  describe "- other" do
126
+ after(:each) do
127
+ Exchange.configuration.implicit_conversions = true
128
+ end
110
129
  it "should be able to subtract an integer" do
111
130
  (subject - 40).value.should == 0
112
131
  end
@@ -126,13 +145,11 @@ describe "Exchange::Money" do
126
145
  it "should raise when currencies get mixed and the configuration does not allow it" do
127
146
  Exchange.configuration.implicit_conversions = false
128
147
  lambda { subject - Exchange::Money.new(30, :chf) }.should raise_error(Exchange::ImplicitConversionError)
129
- Exchange.configuration.implicit_conversions = true
130
148
  end
131
149
  it "should not raise when currencies get mixed and the configuration does not allow if the other currency is the same" do
132
150
  Exchange.configuration.implicit_conversions = false
133
151
  mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
134
152
  lambda { subject - Exchange::Money.new(30, :usd) }.should_not raise_error
135
- Exchange.configuration.implicit_conversions = true
136
153
  end
137
154
  context "modifying the base value" do
138
155
  before(:each) do
@@ -172,6 +189,9 @@ describe "Exchange::Money" do
172
189
  end
173
190
  end
174
191
  describe "* other" do
192
+ after(:each) do
193
+ Exchange.configuration.implicit_conversions = true
194
+ end
175
195
  it "should be able to multiply by an integer" do
176
196
  (subject * 40).value.should == 1600
177
197
  end
@@ -196,13 +216,11 @@ describe "Exchange::Money" do
196
216
  it "should raise when currencies get mixed and the configuration does not allow it" do
197
217
  Exchange.configuration.implicit_conversions = false
198
218
  lambda { subject * Exchange::Money.new(30, :chf) }.should raise_error(Exchange::ImplicitConversionError)
199
- Exchange.configuration.implicit_conversions = true
200
219
  end
201
220
  it "should not raise when currencies get mixed and the configuration does not allow if the other currency is the same" do
202
221
  Exchange.configuration.implicit_conversions = false
203
222
  mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
204
223
  lambda { subject * Exchange::Money.new(30, :usd) }.should_not raise_error
205
- Exchange.configuration.implicit_conversions = true
206
224
  end
207
225
  context "modifying the base value" do
208
226
  before(:each) do
@@ -242,6 +260,9 @@ describe "Exchange::Money" do
242
260
  end
243
261
  end
244
262
  describe "/ other" do
263
+ after(:each) do
264
+ Exchange.configuration.implicit_conversions = true
265
+ end
245
266
  it "should be able to divide by an integer" do
246
267
  (subject / 40).value.should == 1
247
268
  end
@@ -273,13 +294,11 @@ describe "Exchange::Money" do
273
294
  it "should raise when currencies get mixed and the configuration does not allow it" do
274
295
  Exchange.configuration.implicit_conversions = false
275
296
  lambda { subject / Exchange::Money.new(30, :chf) }.should raise_error(Exchange::ImplicitConversionError)
276
- Exchange.configuration.implicit_conversions = true
277
297
  end
278
298
  it "should not raise when currencies get mixed and the configuration does not allow if the other currency is the same" do
279
299
  Exchange.configuration.implicit_conversions = false
280
300
  mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
281
301
  lambda { subject / Exchange::Money.new(30, :usd) }.should_not raise_error
282
- Exchange.configuration.implicit_conversions = true
283
302
  end
284
303
  context "modifying the base value" do
285
304
  before(:each) do
metadata CHANGED
@@ -1,99 +1,89 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: exchange
3
- version: !ruby/object:Gem::Version
4
- hash: 51
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.12.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 11
9
- - 0
10
- version: 0.11.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Beat Richartz
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-10-09 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-10-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: nokogiri
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 23
29
- segments:
30
- - 1
31
- - 0
32
- - 0
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
33
21
  version: 1.0.0
34
22
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: json
38
23
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: json
32
+ requirement: !ruby/object:Gem::Requirement
40
33
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 23
45
- segments:
46
- - 1
47
- - 0
48
- - 0
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
49
37
  version: 1.0.0
50
38
  type: :development
51
- version_requirements: *id002
52
- - !ruby/object:Gem::Dependency
53
- name: yard
54
39
  prerelease: false
55
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: yard
48
+ requirement: !ruby/object:Gem::Requirement
56
49
  none: false
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- hash: 11
61
- segments:
62
- - 0
63
- - 7
64
- - 4
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
65
53
  version: 0.7.4
66
54
  type: :development
67
- version_requirements: *id003
68
- - !ruby/object:Gem::Dependency
69
- name: bundler
70
55
  prerelease: false
71
- requirement: &id004 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.7.4
62
+ - !ruby/object:Gem::Dependency
63
+ name: bundler
64
+ requirement: !ruby/object:Gem::Requirement
72
65
  none: false
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- hash: 23
77
- segments:
78
- - 1
79
- - 0
80
- - 0
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
81
69
  version: 1.0.0
82
70
  type: :development
83
- version_requirements: *id004
84
- description: |-
85
- The Exchange Gem gives you easy access to currency functions directly on your Numbers. Imagine a conversion as easy as
86
- 1.in(:eur).to(:usd) or even better
87
- 1.in(:eur).to(:usd, :at => Time.now - 84600)
88
- which gets you an exchange at the rates of yesterday.
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 1.0.0
78
+ description: ! "The Exchange Gem gives you easy access to currency functions directly
79
+ on your Numbers. Imagine a conversion as easy as \n 1.in(:eur).to(:usd) or even
80
+ better \n 1.in(:eur).to(:usd, :at => Time.now - 84600)\n which gets you an exchange
81
+ at the rates of yesterday."
89
82
  email: exchange_gem@gmail.com
90
83
  executables: []
91
-
92
84
  extensions: []
93
-
94
85
  extra_rdoc_files: []
95
-
96
- files:
86
+ files:
97
87
  - .document
98
88
  - .gitignore
99
89
  - .rspec
@@ -105,7 +95,9 @@ files:
105
95
  - benchmark/benchmark.rb
106
96
  - changelog.rdoc
107
97
  - exchange.gemspec
98
+ - html.html
108
99
  - iso4217.yml
100
+ - iso4217_country_map.yml
109
101
  - lib/exchange.rb
110
102
  - lib/exchange/base.rb
111
103
  - lib/exchange/cache.rb
@@ -134,7 +126,7 @@ files:
134
126
  - lib/exchange/external_api/xml.rb
135
127
  - lib/exchange/gem_loader.rb
136
128
  - lib/exchange/helper.rb
137
- - lib/exchange/iso_4217.rb
129
+ - lib/exchange/iso.rb
138
130
  - lib/exchange/money.rb
139
131
  - lib/exchange/typecasting.rb
140
132
  - spec/exchange/cache/base_spec.rb
@@ -161,7 +153,7 @@ files:
161
153
  - spec/exchange/external_api/xavier_media_spec.rb
162
154
  - spec/exchange/gem_loader_spec.rb
163
155
  - spec/exchange/helper_spec.rb
164
- - spec/exchange/iso_4217_spec.rb
156
+ - spec/exchange/iso_spec.rb
165
157
  - spec/exchange/money_spec.rb
166
158
  - spec/exchange/typecasting_spec.rb
167
159
  - spec/spec_helper.rb
@@ -172,39 +164,31 @@ files:
172
164
  - spec/support/api_responses/example_json_api.json
173
165
  - spec/support/api_responses/example_xml_api.xml
174
166
  homepage: http://beatrichartz.github.com/exchange
175
- licenses:
167
+ licenses:
176
168
  - MIT
177
169
  post_install_message:
178
170
  rdoc_options: []
179
-
180
- require_paths:
171
+ require_paths:
181
172
  - lib
182
- required_ruby_version: !ruby/object:Gem::Requirement
173
+ required_ruby_version: !ruby/object:Gem::Requirement
183
174
  none: false
184
- requirements:
185
- - - ">="
186
- - !ruby/object:Gem::Version
187
- hash: 3
188
- segments:
189
- - 0
190
- version: "0"
191
- required_rubygems_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ! '>='
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ required_rubygems_version: !ruby/object:Gem::Requirement
192
180
  none: false
193
- requirements:
194
- - - ">="
195
- - !ruby/object:Gem::Version
196
- hash: 3
197
- segments:
198
- - 0
199
- version: "0"
181
+ requirements:
182
+ - - ! '>='
183
+ - !ruby/object:Gem::Version
184
+ version: '0'
200
185
  requirements: []
201
-
202
186
  rubyforge_project:
203
187
  rubygems_version: 1.8.24
204
188
  signing_key:
205
189
  specification_version: 3
206
190
  summary: Simple Exchange Rate operations for your ruby app
207
- test_files:
191
+ test_files:
208
192
  - spec/exchange/cache/base_spec.rb
209
193
  - spec/exchange/cache/configuration_spec.rb
210
194
  - spec/exchange/cache/file_spec.rb
@@ -229,7 +213,7 @@ test_files:
229
213
  - spec/exchange/external_api/xavier_media_spec.rb
230
214
  - spec/exchange/gem_loader_spec.rb
231
215
  - spec/exchange/helper_spec.rb
232
- - spec/exchange/iso_4217_spec.rb
216
+ - spec/exchange/iso_spec.rb
233
217
  - spec/exchange/money_spec.rb
234
218
  - spec/exchange/typecasting_spec.rb
235
219
  - spec/spec_helper.rb
@@ -1,233 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Exchange::ISO4217" do
4
- let(:subject) { Exchange::ISO4217 }
5
- describe "self.definitions" do
6
- it "should be a hash of exactly the ISO standard definitions loaded from the yaml file" do
7
- subject.definitions.should === {
8
- :nio => { :minor_unit => 2, :currency => "Cordoba Oro" },
9
- :lak => { :minor_unit => 2, :currency => "Kip" },
10
- :sar => { :format => "#,###.##", :minor_unit => 2, :currency => "Saudi Riyal" },
11
- :nok => { :format => "#.###,##", :minor_unit => 2, :currency => "Norwegian Krone" },
12
- :usd => { :format=>"#,###.##", :minor_unit => 2, :currency => "US Dollar" },
13
- :rub => { :format=>"#.###,##", :minor_unit => 2, :currency => "Russian Ruble" },
14
- :xcd => { :format=>"#,###.##", :minor_unit => 2, :currency => "East Caribbean Dollar" },
15
- :omr => { :format=>"#,###.###", :minor_unit => 3, :currency => "Rial Omani" },
16
- :amd => { :format=>"#,###.##", :minor_unit => 2, :currency => "Armenian Dram" },
17
- :cdf => { :minor_unit => 2, :currency => "Congolese Franc" },
18
- :kpw => { :minor_unit => 2, :currency => "North Korean Won" },
19
- :cny => { :format=>"#,###.##", :minor_unit => 2, :currency => "Yuan Renminbi" },
20
- :kes => { :format=>"#,###.##", :minor_unit => 2, :currency => "Kenyan Shilling" },
21
- :khr => { :minor_unit => 2, :currency => "Riel" },
22
- :pln => { :format=>"# ###,##", :minor_unit => 2, :currency => "Zloty" },
23
- :mvr => { :minor_unit => 2, :currency => "Rufiyaa" },
24
- :gtq => { :format=>"#,###.##", :minor_unit => 2, :currency => "Quetzal" },
25
- :clp => { :format=>"#.###", :minor_unit => 0, :currency => "Chilean Peso" },
26
- :inr => { :format=>"#,##,###.##", :minor_unit => 2, :currency => "Indian Rupee" },
27
- :bzd => { :format=>"#,###.##", :minor_unit => 2, :currency => "Belize Dollar" },
28
- :myr => { :format=>"#,###.##", :minor_unit => 2, :currency => "Malaysian Ringgit" },
29
- :hkd => { :format=>"#,###.##", :minor_unit => 2, :currency => "Hong Kong Dollar" },
30
- :cop => { :format=>"#.###,##", :minor_unit => 2, :currency => "Colombian Peso" },
31
- :dkk => { :format=>"#.###,##", :minor_unit => 2, :currency => "Danish Krone" },
32
- :sek => { :format=>"#.###,##", :minor_unit => 2, :currency => "Swedish Krona" },
33
- :byr => { :minor_unit => 0, :currency => "Belarussian Ruble" },
34
- :lyd => { :minor_unit => 3, :currency => "Libyan Dinar" },
35
- :ron => { :format=>"#.###,##", :minor_unit => 2, :currency => "New Romanian Leu" },
36
- :dzd => { :minor_unit => 2, :currency => "Algerian Dinar" },
37
- :bif => { :minor_unit => 0, :currency => "Burundi Franc" },
38
- :ars => { :format=>"#.###,##", :minor_unit => 2, :currency => "Argentine Peso" },
39
- :gip => { :format=>"#,###.##", :minor_unit => 2, :currency => "Gibraltar Pound" },
40
- :uyi => { :minor_unit => 0, :currency => "Uruguay Peso en Unidades Indexadas (URUIURUI)" },
41
- :bob => { :format=>"#,###.##", :minor_unit => 2, :currency => "Boliviano" },
42
- :ssp => { :minor_unit => 2, :currency => "South Sudanese Pound" },
43
- :ngn => { :minor_unit => 2, :currency => "Naira" },
44
- :pgk => { :minor_unit => 2, :currency => "Kina" },
45
- :std => { :minor_unit => 2, :currency => "Dobra" },
46
- :xof => { :minor_unit => 0, :currency => "CFA Franc BCEAO" },
47
- :aed => { :format=>"#,###.##", :minor_unit => 2, :currency => "UAE Dirham" },
48
- :ern => { :minor_unit => 2, :currency => "Nakfa" },
49
- :mwk => { :minor_unit => 2, :currency => "Kwacha" },
50
- :cup => { :format=>"#,###.##", :minor_unit => 2, :currency => "Cuban Peso" },
51
- :usn => { :minor_unit => 2, :currency => "US Dollar (Next day)" },
52
- :gmd => { :minor_unit => 2, :currency => "Dalasi" },
53
- :cve => { :minor_unit => 2, :currency => "Cape Verde Escudo" },
54
- :tzs => { :format=>"#,###.##", :minor_unit => 2, :currency => "Tanzanian Shilling" },
55
- :cou => { :minor_unit => 2, :currency => "Unidad de Valor Real" },
56
- :btn => { :minor_unit => 2, :currency => "Ngultrum" },
57
- :zwl => { :minor_unit => 2, :currency => "Zimbabwe Dollar" },
58
- :ugx => { :minor_unit => 2, :currency => "Uganda Shilling" },
59
- :syp => { :minor_unit => 2, :currency => "Syrian Pound" },
60
- :mad => { :minor_unit => 2, :currency => "Moroccan Dirham" },
61
- :mnt => { :minor_unit => 2, :currency => "Tugrik" },
62
- :lsl => { :minor_unit => 2, :currency => "Loti" },
63
- :xaf => { :minor_unit => 0, :currency => "CFA Franc BEAC" },
64
- :shp => { :minor_unit => 2, :currency => "Saint Helena Pound" },
65
- :htg => { :minor_unit => 2, :currency => "Gourde" },
66
- :rsd => { :minor_unit => 2, :currency => "Serbian Dinar" },
67
- :mga => { :minor_unit => 2, :currency => "Malagasy Ariary" },
68
- :top => { :format=>"#,###.##", :minor_unit => 2, :currency => "Pa\xE2\x80\x99anga" },
69
- :mzn => { :minor_unit => 2, :currency => "Mozambique Metical" },
70
- :lvl => { :format=>"#,###.##", :minor_unit => 2, :currency => "Latvian Lats" },
71
- :fkp => { :minor_unit => 2, :currency => "Falkland Islands Pound" },
72
- :uss => { :minor_unit => 2, :currency => "US Dollar (Same day)" },
73
- :bwp => { :format=>"#,###.##", :minor_unit => 2, :currency => "Pula" },
74
- :hnl => { :format=>"#,###.##", :minor_unit => 2, :currency => "Lempira" },
75
- :che => { :minor_unit => 2, :currency => "WIR Euro" },
76
- :eur => { :format=>"#,###.##", :minor_unit => 2, :currency => "Euro" },
77
- :egp => { :format=>"#,###.##", :minor_unit => 2, :currency => "Egyptian Pound" },
78
- :chf => { :format=>"#'###.##", :minor_unit => 2, :currency => "Swiss Franc" },
79
- :ils => { :format=>"#,###.##", :minor_unit => 2, :currency => "New Israeli Sheqel" },
80
- :pyg => { :minor_unit => 0, :currency => "Guarani" },
81
- :lbp => { :format=>"# ###", :minor_unit => 2, :currency => "Lebanese Pound" },
82
- :ang => { :format=>"#.###,##", :minor_unit => 2, :currency => "Netherlands Antillean Guilder" },
83
- :kzt => { :minor_unit => 2, :currency => "Tenge" },
84
- :gyd => { :minor_unit => 2, :currency => "Guyana Dollar" },
85
- :wst => { :minor_unit => 2, :currency => "Tala" },
86
- :npr => { :format=>"#,###.##", :minor_unit => 2, :currency => "Nepalese Rupee" },
87
- :kmf => { :minor_unit => 0, :currency => "Comoro Franc" },
88
- :thb => { :format=>"#,###.##", :minor_unit => 2, :currency => "Baht" },
89
- :irr => { :format=>"#,###.##", :minor_unit => 2, :currency => "Iranian Rial" },
90
- :srd => { :minor_unit => 2, :currency => "Surinam Dollar" },
91
- :jpy => { :format=>"#,###", :minor_unit => 0, :currency => "Yen" },
92
- :brl => { :format=>"#.###,##", :minor_unit => 2, :currency => "Brazilian Real" },
93
- :uyu => { :format=>"#.###,##", :minor_unit => 2, :currency => "Peso Uruguayo" },
94
- :mop => { :minor_unit => 2, :currency => "Pataca" },
95
- :bmd => { :format=>"#,###.##", :minor_unit => 2, :currency => "Bermudian Dollar" },
96
- :szl => { :format=>"#, ###.##", :minor_unit => 2, :currency => "Lilangeni" },
97
- :etb => { :minor_unit => 2, :currency => "Ethiopian Birr" },
98
- :jod => { :format=>"#,###.###", :minor_unit => 3, :currency => "Jordanian Dinar" },
99
- :idr => { :format=>"#.###,##", :minor_unit => 2, :currency => "Rupiah" },
100
- :mdl => { :minor_unit => 2, :currency => "Moldovan Leu" },
101
- :xpf => { :minor_unit => 0, :currency => "CFP Franc" },
102
- :mro => { :minor_unit => 2, :currency => "Ouguiya" },
103
- :yer => { :minor_unit => 2, :currency => "Yemeni Rial" },
104
- :bam => { :format=>"#,###.##", :minor_unit => 2, :currency => "Convertible Mark" },
105
- :awg => { :format=>"#,###.##", :minor_unit => 2, :currency => "Aruban Florin" },
106
- :nzd => { :format=>"#,###.##", :minor_unit => 2, :currency => "New Zealand Dollar" },
107
- :pen => { :format=>"#,###.##", :minor_unit => 2, :currency => "Nuevo Sol" },
108
- :aoa => { :minor_unit => 2, :currency => "Kwanza" },
109
- :kyd => { :format=>"#,###.##", :minor_unit => 2, :currency => "Cayman Islands Dollar" },
110
- :sll => { :minor_unit => 2, :currency => "Leone" },
111
- :try => { :format=>"#,###.##", :minor_unit => 2, :currency => "Turkish Lira" },
112
- :vef => { :format=>"#.###,##", :minor_unit => 2, :currency => "Bolivar Fuerte" },
113
- :isk => { :format=>"#.###", :minor_unit => 0, :currency => "Iceland Krona" },
114
- :gnf => { :minor_unit => 0, :currency => "Guinea Franc" },
115
- :bsd => { :format=>"#,###.##", :minor_unit => 2, :currency => "Bahamian Dollar" },
116
- :djf => { :minor_unit => 0, :currency => "Djibouti Franc" },
117
- :huf => { :format=>"#.###", :minor_unit => 2, :currency => "Forint" },
118
- :ltl => { :format=>"# ###,##", :minor_unit => 2, :currency => "Lithuanian Litas" },
119
- :mxn => { :format=>"#,###.##", :minor_unit => 2, :currency => "Mexican Peso" },
120
- :scr => { :minor_unit => 2, :currency => "Seychelles Rupee" },
121
- :sgd => { :format=>"#,###.##", :minor_unit => 2, :currency => "Singapore Dollar" },
122
- :lkr => { :minor_unit => 2, :currency => "Sri Lanka Rupee" },
123
- :tjs => { :minor_unit => 2, :currency => "Somoni" },
124
- :tnd => { :minor_unit => 3, :currency => "Tunisian Dinar" },
125
- :dop => { :format=>"#,###.##", :minor_unit => 2, :currency => "Dominican Peso" },
126
- :fjd => { :minor_unit => 2, :currency => "Fiji Dollar" },
127
- :gel => { :minor_unit => 2, :currency => "Lari" },
128
- :sdg => { :minor_unit => 2, :currency => "Sudanese Pound" },
129
- :vuv => { :format=>"#,###", :minor_unit => 0, :currency => "Vatu" },
130
- :bbd => { :minor_unit => 2, :currency => "Barbados Dollar" },
131
- :lrd => { :minor_unit => 2, :currency => "Liberian Dollar" },
132
- :krw => { :format=>"#,###", :minor_unit => 0, :currency => "Won" },
133
- :mmk => { :minor_unit => 2, :currency => "Kyat" },
134
- :mur => { :format=>"#,###", :minor_unit => 2, :currency => "Mauritius Rupee" },
135
- :php => { :format=>"#,###.##", :minor_unit => 2, :currency => "Philippine Peso" },
136
- :zar => { :format=>"# ###.##", :minor_unit => 2, :currency => "Rand" },
137
- :kgs => { :minor_unit => 2, :currency => "Som" },
138
- :gbp => { :format=>"#,###.##", :minor_unit => 2, :currency => "Pound Sterling" },
139
- :bgn => { :minor_unit => 2, :currency => "Bulgarian Lev" },
140
- :iqd => { :minor_unit => 3, :currency => "Iraqi Dinar" },
141
- :tmt => { :minor_unit => 2, :currency => "Turkmenistan New Manat" },
142
- :uah => { :format=>"# ###,##", :minor_unit => 2, :currency => "Hryvnia" },
143
- :vnd => { :format=>"#.###", :minor_unit => 0, :currency => "Dong" },
144
- :zmk => { :minor_unit => 2, :currency => "Zambian Kwacha" },
145
- :bov => { :minor_unit => 2, :currency => "Mvdol" },
146
- :hrk => { :format=>"#.###,##", :minor_unit => 2, :currency => "Croatian Kuna" },
147
- :ttd => { :minor_unit => 2, :currency => "Trinidad and Tobago Dollar" },
148
- :bhd => { :format=>"#,###.###", :minor_unit => 3, :currency => "Bahraini Dinar" },
149
- :clf => { :minor_unit => 0, :currency => "Unidades de fomento" },
150
- :rwf => { :minor_unit => 0, :currency => "Rwanda Franc" },
151
- :mkd => { :format=>"#,###.##", :minor_unit => 2, :currency => "Denar" },
152
- :aud => { :format=>"# ###.##", :minor_unit => 2, :currency => "Australian Dollar" },
153
- :crc => { :format=>"#.###,##", :minor_unit => 2, :currency => "Costa Rican Colon" },
154
- :pkr => { :format=>"#,###.##", :minor_unit => 2, :currency => "Pakistan Rupee" },
155
- :twd => { :minor_unit => 2, :currency => "New Taiwan Dollar" },
156
- :uzs => { :minor_unit => 2, :currency => "Uzbekistan Sum" },
157
- :czk => { :format=>"#.###,##", :minor_unit => 2, :currency => "Czech Koruna" },
158
- :azn => { :minor_unit => 2, :currency => "Azerbaijanian Manat" },
159
- :bdt => { :format=>"#,###.##", :minor_unit => 2, :currency => "Taka" },
160
- :nad => { :minor_unit => 2, :currency => "Namibia Dollar" },
161
- :afn => { :minor_unit => 2, :currency => "Afghani" },
162
- :mxv => { :minor_unit => 2, :currency => "Mexican Unidad de Inversion (UDI)" },
163
- :cuc => { :format=>"#,###.##", :minor_unit => 2, :currency => "Peso Convertible" },
164
- :pab => { :minor_unit => 2, :currency => "Balboa" },
165
- :qar => { :minor_unit => 2, :currency => "Qatari Rial" },
166
- :sos => { :minor_unit => 2, :currency => "Somali Shilling" },
167
- :chw => { :minor_unit => 2, :currency => "WIR Franc" },
168
- :cad => { :format=>"#,###.##", :minor_unit => 2, :currency => "Canadian Dollar" },
169
- :jmd => { :format=>"#,###.##", :minor_unit => 2, :currency => "Jamaican Dollar" },
170
- :bnd => { :format=>"#,###.##", :minor_unit => 2, :currency => "Brunei Dollar" },
171
- :all => { :minor_unit => 2, :currency => "Lek" },
172
- :svc => { :format=>"#,###.##", :minor_unit => 2, :currency => "El Salvador Colon" },
173
- :sbd => { :minor_unit => 2, :currency => "Solomon Islands Dollar" },
174
- :ghs => { :minor_unit => 2, :currency => "Ghana Cedi" },
175
- :kwd => { :format=>"#,###.###", :minor_unit => 3, :currency => "Kuwaiti Dinar" }
176
- }
177
- end
178
- end
179
- describe "self.currencies" do
180
- it "should be an array of currency symbols" do
181
- subject.currencies.should == %W(nio lak sar nok usd rub xcd omr amd cdf kpw cny kes khr pln mvr gtq clp inr bzd myr hkd cop dkk sek byr lyd ron dzd bif ars gip uyi bob ssp ngn pgk std xof aed ern mwk cup usn gmd cve tzs cou btn zwl ugx syp mad mnt lsl xaf shp htg rsd mga top mzn lvl fkp uss bwp hnl che eur egp chf ils pyg lbp ang kzt gyd wst npr kmf thb irr srd jpy brl uyu mop bmd szl etb jod idr mdl xpf mro yer bam awg nzd pen aoa kyd sll try vef isk gnf bsd djf huf ltl mxn scr sgd lkr tjs tnd dop fjd gel sdg vuv bbd lrd krw mmk mur php zar kgs gbp bgn iqd tmt uah vnd zmk bov hrk ttd bhd clf rwf mkd aud crc pkr twd uzs czk azn bdt nad afn mxv cuc pab qar sos chw cad jmd bnd all svc sbd ghs kwd).sort.map(&:to_sym)
182
- end
183
- end
184
- describe "self.defines?" do
185
- context "with a defined currency" do
186
- it "should return true" do
187
- subject.currencies.each do |curr|
188
- subject.should be_defines(curr)
189
- end
190
- end
191
- end
192
- context "with an undefined currency" do
193
- it "should return false" do
194
- subject.should_not be_defines(:xxx)
195
- end
196
- end
197
- end
198
- describe "self.instantiate" do
199
- it "should instantiate a big decimal according to the iso standards" do
200
- BigDecimal.should_receive(:new).with('23.23', 3).and_return('INSTANCE')
201
- subject.instantiate(23.23, :tnd).should == 'INSTANCE'
202
- BigDecimal.should_receive(:new).with('23.23', 2).and_return('INSTANCE')
203
- subject.instantiate(23.23, :sar).should == 'INSTANCE'
204
- BigDecimal.should_receive(:new).with('23.23', 0).and_return('INSTANCE')
205
- subject.instantiate(23.23, :clp).should == 'INSTANCE'
206
- end
207
- end
208
- describe "self.round" do
209
- it "should round a currency according to ISO 4217 Definitions" do
210
- subject.round(BigDecimal.new("23.232524"), :tnd).should == BigDecimal.new("23.233")
211
- subject.round(BigDecimal.new("23.232524"), :sar).should == BigDecimal.new("23.23")
212
- subject.round(BigDecimal.new("23.232524"), :clp).should == BigDecimal.new("23")
213
- end
214
- end
215
- describe "self.stringify" do
216
- it "should stringify a currency according to ISO 4217 Definitions" do
217
- subject.stringify(BigDecimal.new("23.232524"), :tnd).should == "TND 23.233"
218
- subject.stringify(BigDecimal.new("23.232524"), :sar).should == "SAR 23.23"
219
- subject.stringify(BigDecimal.new("23.232524"), :clp).should == "CLP 23"
220
- subject.stringify(BigDecimal.new("23.2"), :tnd).should == "TND 23.200"
221
- subject.stringify(BigDecimal.new("23.4"), :sar).should == "SAR 23.40"
222
- subject.stringify(BigDecimal.new("23.0"), :clp).should == "CLP 23"
223
- end
224
- it "should not render the currency if only the amount is wished for" do
225
- subject.stringify(BigDecimal.new("23.232524"), :tnd, :amount_only => true).should == "23.233"
226
- subject.stringify(BigDecimal.new("23.232524"), :sar, :amount_only => true).should == "23.23"
227
- subject.stringify(BigDecimal.new("23.232524"), :clp, :amount_only => true).should == "23"
228
- subject.stringify(BigDecimal.new("23.2"), :tnd, :amount_only => true).should == "23.200"
229
- subject.stringify(BigDecimal.new("23.4"), :sar, :amount_only => true).should == "23.40"
230
- subject.stringify(BigDecimal.new("23.0"), :clp, :amount_only => true).should == "23"
231
- end
232
- end
233
- end