exchange 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,6 +26,16 @@ describe "Exchange::CacheDalli::Client" do
26
26
  subject.client.should == client
27
27
  end
28
28
  end
29
+ describe "wipe_client!" do
30
+ let(:client) { mock('memcached') }
31
+
32
+ it "should set the client to nil" do
33
+ Dalli::Client.should_receive(:new).with("HOST:PORT").and_return(client)
34
+ subject.client.should == client
35
+ subject.wipe_client!
36
+ subject.instance_variable_get("@client").should be_nil
37
+ end
38
+ end
29
39
  describe "cached" do
30
40
  let(:client) { mock('memcached', :get => '') }
31
41
  before(:each) do
@@ -38,7 +38,7 @@ describe "Exchange::Conversability" do
38
38
  3.in(:chf, :at => '2010-01-01').time.year.should == 2010
39
39
  end
40
40
  it "should raise a no currency error if the currency does not exist" do
41
- lambda { 35.in(:zzz) }.should raise_error(Exchange::NoCurrencyError, "zzz is not a currency")
41
+ lambda { 35.in(:zzz) }.should raise_error(Exchange::NoCurrencyError, "zzz is not a currency nor a country code matchable to a currency")
42
42
  end
43
43
  end
44
44
  context "with a float" do
@@ -68,7 +68,7 @@ describe "Exchange::Conversability" do
68
68
  3.25.in(:chf, :at => '2010-01-01').time.year.should == 2010
69
69
  end
70
70
  it "should raise a no currency error if the currency does not exist" do
71
- lambda { 35.23.in(:zzz) }.should raise_error(Exchange::NoCurrencyError, "zzz is not a currency")
71
+ lambda { 35.23.in(:zzz) }.should raise_error(Exchange::NoCurrencyError, "zzz is not a currency nor a country code matchable to a currency")
72
72
  end
73
73
  end
74
74
  context "with a big decimal" do
@@ -98,7 +98,7 @@ describe "Exchange::Conversability" do
98
98
  BigDecimal.new("3.25").in(:chf, :at => '2010-01-01').time.year.should == 2010
99
99
  end
100
100
  it "should raise a no currency error if the currency does not exist" do
101
- lambda { BigDecimal.new("3.25").in(:zzz) }.should raise_error(Exchange::NoCurrencyError, "zzz is not a currency")
101
+ lambda { BigDecimal.new("3.25").in(:zzz) }.should raise_error(Exchange::NoCurrencyError, "zzz is not a currency nor a country code matchable to a currency")
102
102
  end
103
103
  end
104
104
  end
@@ -0,0 +1,795 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe "Exchange::ISO" do
6
+ let(:subject) { Exchange::ISO }
7
+ describe "self.definitions" do
8
+ it "should be a hash of exactly the ISO standard definitions loaded from the yaml file" do
9
+ subject.definitions.should === {
10
+ :aed => {:format=>"#,###.##", :minor_unit=>2, :currency=>"UAE Dirham", :symbol=>nil},
11
+ :afn => {:minor_unit=>2, :currency=>"Afghani", :symbol=>"؋"},
12
+ :all => {:minor_unit=>2, :currency=>"Lek", :symbol=>"Lek"},
13
+ :amd => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Armenian Dram", :symbol=>nil},
14
+ :ang => {:format=>"#.###,##", :minor_unit=>2, :currency=>"Netherlands Antillean Guilder", :symbol=>"ƒ"},
15
+ :aoa => {:minor_unit=>2, :currency=>"Kwanza", :symbol=>nil},
16
+ :ars => {:format=>"#.###,##", :minor_unit=>2, :currency=>"Argentine Peso", :symbol=>"$"},
17
+ :aud => {:format=>"# ###.##", :minor_unit=>2, :currency=>"Australian Dollar", :symbol=>"$"},
18
+ :awg => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Aruban Florin", :symbol=>"ƒ"},
19
+ :azn => {:minor_unit=>2, :currency=>"Azerbaijanian Manat", :symbol=>"ман"},
20
+ :bam => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Convertible Mark", :symbol=>"KM"},
21
+ :bbd => {:minor_unit=>2, :currency=>"Barbados Dollar", :symbol=>"$"},
22
+ :bdt => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Taka", :symbol=>nil},
23
+ :bgn => {:minor_unit=>2, :currency=>"Bulgarian Lev", :symbol=>"лв"},
24
+ :bhd => {:format=>"#,###.###", :minor_unit=>3, :currency=>"Bahraini Dinar", :symbol=>nil},
25
+ :bif => {:minor_unit=>0, :currency=>"Burundi Franc", :symbol=>nil},
26
+ :bmd => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Bermudian Dollar", :symbol=>"$"},
27
+ :bnd => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Brunei Dollar", :symbol=>"$"},
28
+ :bob => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Boliviano", :symbol=>"$b"},
29
+ :bov => {:minor_unit=>2, :currency=>"Mvdol", :symbol=>nil},
30
+ :brl => {:format=>"#.###,##", :minor_unit=>2, :currency=>"Brazilian Real", :symbol=>"R$"},
31
+ :bsd => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Bahamian Dollar", :symbol=>"$"},
32
+ :btn => {:minor_unit=>2, :currency=>"Ngultrum", :symbol=>nil},
33
+ :bwp => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Pula", :symbol=>"P"},
34
+ :byr => {:minor_unit=>0, :currency=>"Belarussian Ruble", :symbol=>"p."},
35
+ :bzd => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Belize Dollar", :symbol=>"BZ$"},
36
+ :cad => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Canadian Dollar", :symbol=>"$"},
37
+ :cdf => {:minor_unit=>2, :currency=>"Congolese Franc", :symbol=>nil},
38
+ :chf => {:format=>"#'###.##", :minor_unit=>2, :currency=>"Swiss Franc", :symbol=>"CHF"},
39
+ :chw => {:minor_unit=>2, :currency=>"WIR Franc", :symbol=>nil},
40
+ :clf => {:minor_unit=>0, :currency=>"Unidades de fomento", :symbol=>nil},
41
+ :clp => {:format=>"#.###", :minor_unit=>0, :currency=>"Chilean Peso", :symbol=>"$"},
42
+ :cny => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Yuan Renminbi", :symbol=>"¥"},
43
+ :cop => {:format=>"#.###,##", :minor_unit=>2, :currency=>"Colombian Peso", :symbol=>"$"},
44
+ :cou => {:minor_unit=>2, :currency=>"Unidad de Valor Real", :symbol=>nil},
45
+ :crc => {:format=>"#.###,##", :minor_unit=>2, :currency=>"Costa Rican Colon", :symbol=>"₡"},
46
+ :cuc => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Peso Convertible", :symbol=>nil},
47
+ :cup => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Cuban Peso", :symbol=>"₱"},
48
+ :cve => {:minor_unit=>2, :currency=>"Cape Verde Escudo", :symbol=>nil},
49
+ :czk => {:format=>"#.###,##", :minor_unit=>2, :currency=>"Czech Koruna", :symbol=>"Kč"},
50
+ :djf => {:minor_unit=>0, :currency=>"Djibouti Franc", :symbol=>nil},
51
+ :dkk => {:format=>"#.###,##", :minor_unit=>2, :currency=>"Danish Krone", :symbol=>"kr"},
52
+ :dop => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Dominican Peso", :symbol=>"RD$"},
53
+ :dzd => {:minor_unit=>2, :currency=>"Algerian Dinar", :symbol=>nil},
54
+ :egp => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Egyptian Pound", :symbol=>"£"},
55
+ :ern => {:minor_unit=>2, :currency=>"Nakfa", :symbol=>nil},
56
+ :etb => {:minor_unit=>2, :currency=>"Ethiopian Birr", :symbol=>nil},
57
+ :eur => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Euro", :symbol=>"€"},
58
+ :fjd => {:minor_unit=>2, :currency=>"Fiji Dollar", :symbol=>"$"},
59
+ :fkp => {:minor_unit=>2, :currency=>"Falkland Islands Pound", :symbol=>"£"},
60
+ :gbp => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Pound Sterling", :symbol=>"£"},
61
+ :gel => {:minor_unit=>2, :currency=>"Lari", :symbol=>nil},
62
+ :ghs => {:minor_unit=>2, :currency=>"Ghana Cedi", :symbol=>nil},
63
+ :gip => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Gibraltar Pound", :symbol=>"£"},
64
+ :gmd => {:minor_unit=>2, :currency=>"Dalasi", :symbol=>nil},
65
+ :gnf => {:minor_unit=>0, :currency=>"Guinea Franc", :symbol=>nil},
66
+ :gtq => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Quetzal", :symbol=>"Q"},
67
+ :gyd => {:minor_unit=>2, :currency=>"Guyana Dollar", :symbol=>"$"},
68
+ :hkd => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Hong Kong Dollar", :symbol=>"$"},
69
+ :hnl => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Lempira", :symbol=>"L"},
70
+ :hrk => {:format=>"#.###,##", :minor_unit=>2, :currency=>"Croatian Kuna", :symbol=>"kn"},
71
+ :htg => {:minor_unit=>2, :currency=>"Gourde", :symbol=>nil},
72
+ :huf => {:format=>"#.###", :minor_unit=>2, :currency=>"Forint", :symbol=>"Ft"},
73
+ :idr => {:format=>"#.###,##", :minor_unit=>2, :currency=>"Rupiah", :symbol=>"Rp"},
74
+ :ils => {:format=>"#,###.##", :minor_unit=>2, :currency=>"New Israeli Sheqel", :symbol=>"₪"},
75
+ :inr => {:format=>"#,##,###.##", :minor_unit=>2, :currency=>"Indian Rupee", :symbol=>""},
76
+ :iqd => {:minor_unit=>3, :currency=>"Iraqi Dinar", :symbol=>nil},
77
+ :irr => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Iranian Rial", :symbol=>"﷼"},
78
+ :isk => {:format=>"#.###", :minor_unit=>0, :currency=>"Iceland Krona", :symbol=>"kr"},
79
+ :jmd => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Jamaican Dollar", :symbol=>"J$"},
80
+ :jod => {:format=>"#,###.###", :minor_unit=>3, :currency=>"Jordanian Dinar", :symbol=>nil},
81
+ :jpy => {:format=>"#,###", :minor_unit=>0, :currency=>"Yen", :symbol=>"¥"},
82
+ :kes => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Kenyan Shilling", :symbol=>nil},
83
+ :kgs => {:minor_unit=>2, :currency=>"Som", :symbol=>"лв"},
84
+ :khr => {:minor_unit=>2, :currency=>"Riel", :symbol=>"៛"},
85
+ :kmf => {:minor_unit=>0, :currency=>"Comoro Franc", :symbol=>nil},
86
+ :kpw => {:minor_unit=>2, :currency=>"North Korean Won", :symbol=>"₩"},
87
+ :krw => {:format=>"#,###", :minor_unit=>0, :currency=>"Won", :symbol=>"₩"},
88
+ :kwd => {:format=>"#,###.###", :minor_unit=>3, :currency=>"Kuwaiti Dinar", :symbol=>nil},
89
+ :kyd => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Cayman Islands Dollar", :symbol=>"$"},
90
+ :kzt => {:minor_unit=>2, :currency=>"Tenge", :symbol=>"лв"},
91
+ :lak => {:minor_unit=>2, :currency=>"Kip", :symbol=>"₭"},
92
+ :lbp => {:format=>"# ###", :minor_unit=>2, :currency=>"Lebanese Pound", :symbol=>"£"},
93
+ :lkr => {:minor_unit=>2, :currency=>"Sri Lanka Rupee", :symbol=>"₨"},
94
+ :lrd => {:minor_unit=>2, :currency=>"Liberian Dollar", :symbol=>"$"},
95
+ :lsl => {:minor_unit=>2, :currency=>"Loti", :symbol=>nil},
96
+ :ltl => {:format=>"# ###,##", :minor_unit=>2, :currency=>"Lithuanian Litas", :symbol=>"Lt"},
97
+ :lvl => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Latvian Lats", :symbol=>"Ls"},
98
+ :lyd => {:minor_unit=>3, :currency=>"Libyan Dinar", :symbol=>nil},
99
+ :mad => {:minor_unit=>2, :currency=>"Moroccan Dirham", :symbol=>nil},
100
+ :mdl => {:minor_unit=>2, :currency=>"Moldovan Leu", :symbol=>nil},
101
+ :mga => {:minor_unit=>2, :currency=>"Malagasy Ariary", :symbol=>nil},
102
+ :mkd => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Denar", :symbol=>"ден"},
103
+ :mmk => {:minor_unit=>2, :currency=>"Kyat", :symbol=>nil},
104
+ :mnt => {:minor_unit=>2, :currency=>"Tugrik", :symbol=>"₮"},
105
+ :mop => {:minor_unit=>2, :currency=>"Pataca", :symbol=>nil},
106
+ :mro => {:minor_unit=>2, :currency=>"Ouguiya", :symbol=>nil},
107
+ :mur => {:format=>"#,###", :minor_unit=>2, :currency=>"Mauritius Rupee", :symbol=>"₨"},
108
+ :mvr => {:minor_unit=>2, :currency=>"Rufiyaa", :symbol=>nil},
109
+ :mwk => {:minor_unit=>2, :currency=>"Kwacha", :symbol=>nil},
110
+ :mxn => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Mexican Peso", :symbol=>"$"},
111
+ :mxv => {:minor_unit=>2, :currency=>"Mexican Unidad de Inversion (UDI)", :symbol=>nil},
112
+ :myr => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Malaysian Ringgit", :symbol=>"RM"},
113
+ :mzn => {:minor_unit=>2, :currency=>"Mozambique Metical", :symbol=>"MT"},
114
+ :nad => {:minor_unit=>2, :currency=>"Namibia Dollar", :symbol=>"$"},
115
+ :ngn => {:minor_unit=>2, :currency=>"Naira", :symbol=>"₦"},
116
+ :nio => {:minor_unit=>2, :currency=>"Cordoba Oro", :symbol=>"C$"},
117
+ :nok => {:format=>"#.###,##", :minor_unit=>2, :currency=>"Norwegian Krone", :symbol=>"kr"},
118
+ :npr => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Nepalese Rupee", :symbol=>"₨"},
119
+ :nzd => {:format=>"#,###.##", :minor_unit=>2, :currency=>"New Zealand Dollar", :symbol=>"$"},
120
+ :omr => {:format=>"#,###.###", :minor_unit=>3, :currency=>"Rial Omani", :symbol=>"﷼"},
121
+ :pab => {:minor_unit=>2, :currency=>"Balboa", :symbol=>"B/."},
122
+ :pen => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Nuevo Sol", :symbol=>"S/."},
123
+ :pgk => {:minor_unit=>2, :currency=>"Kina", :symbol=>nil},
124
+ :php => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Philippine Peso", :symbol=>"₱"},
125
+ :pkr => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Pakistan Rupee", :symbol=>"₨"},
126
+ :pln => {:format=>"# ###,##", :minor_unit=>2, :currency=>"Zloty", :symbol=>"zł"},
127
+ :pyg => {:minor_unit=>0, :currency=>"Guarani", :symbol=>"Gs"},
128
+ :qar => {:minor_unit=>2, :currency=>"Qatari Rial", :symbol=>"﷼"},
129
+ :ron => {:format=>"#.###,##", :minor_unit=>2, :currency=>"New Romanian Leu", :symbol=>"lei"},
130
+ :rsd => {:minor_unit=>2, :currency=>"Serbian Dinar", :symbol=>"Дин."},
131
+ :rub => {:format=>"#.###,##", :minor_unit=>2, :currency=>"Russian Ruble", :symbol=>"руб"},
132
+ :rwf => {:minor_unit=>0, :currency=>"Rwanda Franc", :symbol=>nil},
133
+ :sar => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Saudi Riyal", :symbol=>"﷼"},
134
+ :sbd => {:minor_unit=>2, :currency=>"Solomon Islands Dollar", :symbol=>"$"},
135
+ :scr => {:minor_unit=>2, :currency=>"Seychelles Rupee", :symbol=>"₨"},
136
+ :sdg => {:minor_unit=>2, :currency=>"Sudanese Pound", :symbol=>nil},
137
+ :sek => {:format=>"#.###,##", :minor_unit=>2, :currency=>"Swedish Krona", :symbol=>"kr"},
138
+ :sgd => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Singapore Dollar", :symbol=>"$"},
139
+ :shp => {:minor_unit=>2, :currency=>"Saint Helena Pound", :symbol=>"£"},
140
+ :sll => {:minor_unit=>2, :currency=>"Leone", :symbol=>nil},
141
+ :sos => {:minor_unit=>2, :currency=>"Somali Shilling", :symbol=>"S"},
142
+ :srd => {:minor_unit=>2, :currency=>"Surinam Dollar", :symbol=>"$"},
143
+ :ssp => {:minor_unit=>2, :currency=>"South Sudanese Pound", :symbol=>nil},
144
+ :std => {:minor_unit=>2, :currency=>"Dobra", :symbol=>nil},
145
+ :svc => {:format=>"#,###.##", :minor_unit=>2, :currency=>"El Salvador Colon", :symbol=>"$"},
146
+ :syp => {:minor_unit=>2, :currency=>"Syrian Pound", :symbol=>"£"},
147
+ :szl => {:format=>"#, ###.##", :minor_unit=>2, :currency=>"Lilangeni", :symbol=>nil},
148
+ :thb => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Baht", :symbol=>"฿"},
149
+ :tjs => {:minor_unit=>2, :currency=>"Somoni", :symbol=>nil},
150
+ :tmt => {:minor_unit=>2, :currency=>"Turkmenistan New Manat", :symbol=>nil},
151
+ :tnd => {:minor_unit=>3, :currency=>"Tunisian Dinar", :symbol=>nil},
152
+ :top => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Pa\xE2\x80\x99anga", :symbol=>nil},
153
+ :try => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Turkish Lira", :symbol=>""},
154
+ :ttd => {:minor_unit=>2, :currency=>"Trinidad and Tobago Dollar", :symbol=>"TT$"},
155
+ :twd => {:minor_unit=>2, :currency=>"New Taiwan Dollar", :symbol=>"NT$"},
156
+ :tzs => {:format=>"#,###.##", :minor_unit=>2, :currency=>"Tanzanian Shilling", :symbol=>nil},
157
+ :uah => {:format=>"# ###,##", :minor_unit=>2, :currency=>"Hryvnia", :symbol=>"₴"},
158
+ :ugx => {:minor_unit=>2, :currency=>"Uganda Shilling", :symbol=>nil},
159
+ :usd => {:format=>"#,###.##", :minor_unit=>2, :currency=>"US Dollar", :symbol=>"$"},
160
+ :usn => {:minor_unit=>2, :currency=>"US Dollar (Next day)", :symbol=>nil},
161
+ :uss => {:minor_unit=>2, :currency=>"US Dollar (Same day)", :symbol=>nil},
162
+ :uyi => {:minor_unit=>0, :currency=>"Uruguay Peso en Unidades Indexadas (URUIURUI)", :symbol=>nil},
163
+ :uyu => {:format=>"#.###,##", :minor_unit=>2, :currency=>"Peso Uruguayo", :symbol=>"$U"},
164
+ :uzs => {:minor_unit=>2, :currency=>"Uzbekistan Sum", :symbol=>"лв"},
165
+ :vef => {:format=>"#.###,##", :minor_unit=>2, :currency=>"Bolivar Fuerte", :symbol=>"Bs"},
166
+ :vnd => {:format=>"#.###", :minor_unit=>0, :currency=>"Dong", :symbol=>"₫"},
167
+ :vuv => {:format=>"#,###", :minor_unit=>0, :currency=>"Vatu", :symbol=>nil},
168
+ :wst => {:minor_unit=>2, :currency=>"Tala", :symbol=>nil},
169
+ :xaf => {:minor_unit=>0, :currency=>"CFA Franc BEAC", :symbol=>nil},
170
+ :xcd => {:format=>"#,###.##", :minor_unit=>2, :currency=>"East Caribbean Dollar", :symbol=>"$"},
171
+ :xof => {:minor_unit=>0, :currency=>"CFA Franc BCEAO", :symbol=>nil},
172
+ :xpf => {:minor_unit=>0, :currency=>"CFP Franc", :symbol=>nil},
173
+ :yer => {:minor_unit=>2, :currency=>"Yemeni Rial", :symbol=>"﷼"},
174
+ :zar => {:format=>"# ###.##", :minor_unit=>2, :currency=>"Rand", :symbol=>"R"},
175
+ :zmk => {:minor_unit=>2, :currency=>"Zambian Kwacha", :symbol=>nil},
176
+ :zwl => {:minor_unit=>2, :currency=>"Zimbabwe Dollar", :symbol=>nil}
177
+ }
178
+ end
179
+ end
180
+ describe "self.country_map" do
181
+ it "should deliver a complete map of country abbreviations to currencies" do
182
+ subject.country_map.should == {
183
+ :abw => :awg,
184
+ :ad => :eur,
185
+ :ae => :aed,
186
+ :af => :afn,
187
+ :afg => :afn,
188
+ :ag => :xcd,
189
+ :ago => :aoa,
190
+ :ai => :xcd,
191
+ :aia => :xcd,
192
+ :al => :all,
193
+ :ala => :eur,
194
+ :alb => :all,
195
+ :am => :amd,
196
+ :and => :eur,
197
+ :ao => :aoa,
198
+ :ar => :ars,
199
+ :are => :aed,
200
+ :arg => :ars,
201
+ :arm => :amd,
202
+ :as => :usd,
203
+ :asm => :usd,
204
+ :at => :eur,
205
+ :atf => :eur,
206
+ :atg => :xcd,
207
+ :au => :aud,
208
+ :aus => :aud,
209
+ :aut => :eur,
210
+ :aw => :awg,
211
+ :ax => :eur,
212
+ :az => :azn,
213
+ :aze => :azn,
214
+ :ba => :bam,
215
+ :bb => :bbd,
216
+ :bd => :bdt,
217
+ :bdi => :bif,
218
+ :be => :eur,
219
+ :bel => :eur,
220
+ :ben => :xof,
221
+ :bes => :usd,
222
+ :bf => :xof,
223
+ :bfa => :xof,
224
+ :bg => :bgn,
225
+ :bgd => :bdt,
226
+ :bgr => :bgn,
227
+ :bh => :bhd,
228
+ :bhr => :bhd,
229
+ :bhs => :bsd,
230
+ :bi => :bif,
231
+ :bih => :bam,
232
+ :bj => :xof,
233
+ :bl => :eur,
234
+ :blm => :eur,
235
+ :blr => :byr,
236
+ :blz => :bzd,
237
+ :bm => :bmd,
238
+ :bmu => :bmd,
239
+ :bn => :bnd,
240
+ :bo => :bov,
241
+ :bol => :bov,
242
+ :bq => :usd,
243
+ :br => :brl,
244
+ :bra => :brl,
245
+ :brb => :bbd,
246
+ :brn => :bnd,
247
+ :bs => :bsd,
248
+ :bt => :btn,
249
+ :btn => :btn,
250
+ :bv => :nok,
251
+ :bvt => :nok,
252
+ :bw => :bwp,
253
+ :bwa => :bwp,
254
+ :by => :byr,
255
+ :bz => :bzd,
256
+ :ca => :cad,
257
+ :caf => :xaf,
258
+ :can => :cad,
259
+ :cc => :aud,
260
+ :cck => :aud,
261
+ :cd => :cdf,
262
+ :cf => :xaf,
263
+ :cg => :xaf,
264
+ :ch => :chf,
265
+ :che => :chf,
266
+ :chl => :clf,
267
+ :chn => :cny,
268
+ :ci => :xof,
269
+ :civ => :xof,
270
+ :ck => :nzd,
271
+ :cl => :clf,
272
+ :cm => :xaf,
273
+ :cmr => :xaf,
274
+ :cn => :cny,
275
+ :co => :cou,
276
+ :cod => :cdf,
277
+ :cog => :xaf,
278
+ :cok => :nzd,
279
+ :col => :cou,
280
+ :com => :kmf,
281
+ :cpv => :cve,
282
+ :cr => :crc,
283
+ :cri => :crc,
284
+ :cu => :cuc,
285
+ :cub => :cuc,
286
+ :cuw => :ang,
287
+ :cv => :cve,
288
+ :cw => :ang,
289
+ :cx => :aud,
290
+ :cxr => :aud,
291
+ :cy => :eur,
292
+ :cym => :kyd,
293
+ :cyp => :eur,
294
+ :cz => :czk,
295
+ :cze => :czk,
296
+ :de => :eur,
297
+ :deu => :eur,
298
+ :dj => :djf,
299
+ :dji => :djf,
300
+ :dk => :dkk,
301
+ :dm => :xcd,
302
+ :dma => :xcd,
303
+ :dnk => :dkk,
304
+ :do => :dop,
305
+ :dom => :dop,
306
+ :dz => :dzd,
307
+ :dza => :dzd,
308
+ :ec => :usd,
309
+ :ecu => :usd,
310
+ :ee => :eur,
311
+ :eg => :egp,
312
+ :egy => :egp,
313
+ :eh => :mad,
314
+ :er => :ern,
315
+ :eri => :ern,
316
+ :es => :eur,
317
+ :esh => :mad,
318
+ :esp => :eur,
319
+ :est => :eur,
320
+ :et => :etb,
321
+ :eth => :etb,
322
+ :fi => :eur,
323
+ :fin => :eur,
324
+ :fj => :fjd,
325
+ :fji => :fjd,
326
+ :fk => :fkp,
327
+ :flk => :fkp,
328
+ :fm => :usd,
329
+ :fo => :dkk,
330
+ :fr => :eur,
331
+ :fra => :eur,
332
+ :fro => :dkk,
333
+ :fsm => :usd,
334
+ :ga => :xaf,
335
+ :gab => :xaf,
336
+ :gb => :gbp,
337
+ :gbr => :gbp,
338
+ :gd => :xcd,
339
+ :ge => :gel,
340
+ :geo => :gel,
341
+ :gf => :eur,
342
+ :gg => :gbp,
343
+ :ggy => :gbp,
344
+ :gh => :ghs,
345
+ :gha => :ghs,
346
+ :gi => :gip,
347
+ :gib => :gip,
348
+ :gin => :gnf,
349
+ :gl => :dkk,
350
+ :glp => :eur,
351
+ :gm => :gmd,
352
+ :gmb => :gmd,
353
+ :gn => :gnf,
354
+ :gnb => :xof,
355
+ :gnq => :xaf,
356
+ :gp => :eur,
357
+ :gq => :xaf,
358
+ :gr => :eur,
359
+ :grc => :eur,
360
+ :grd => :xcd,
361
+ :grl => :dkk,
362
+ :gt => :gtq,
363
+ :gtm => :gtq,
364
+ :gu => :usd,
365
+ :guf => :eur,
366
+ :gum => :usd,
367
+ :guy => :gyd,
368
+ :gw => :xof,
369
+ :gy => :gyd,
370
+ :hk => :hkd,
371
+ :hkg => :hkd,
372
+ :hm => :aud,
373
+ :hmd => :aud,
374
+ :hn => :hnl,
375
+ :hnd => :hnl,
376
+ :hr => :hrk,
377
+ :hrv => :hrk,
378
+ :ht => :usd,
379
+ :hti => :usd,
380
+ :hu => :huf,
381
+ :hun => :huf,
382
+ :id => :idr,
383
+ :idn => :idr,
384
+ :ie => :eur,
385
+ :il => :ils,
386
+ :im => :gbp,
387
+ :imn => :gbp,
388
+ :in => :inr,
389
+ :ind => :inr,
390
+ :io => :usd,
391
+ :iot => :usd,
392
+ :iq => :iqd,
393
+ :ir => :irr,
394
+ :irl => :eur,
395
+ :irn => :irr,
396
+ :irq => :iqd,
397
+ :is => :isk,
398
+ :isl => :isk,
399
+ :isr => :ils,
400
+ :it => :eur,
401
+ :ita => :eur,
402
+ :jam => :jmd,
403
+ :je => :gbp,
404
+ :jey => :gbp,
405
+ :jm => :jmd,
406
+ :jo => :jod,
407
+ :jor => :jod,
408
+ :jp => :jpy,
409
+ :jpn => :jpy,
410
+ :kaz => :kzt,
411
+ :ke => :kes,
412
+ :ken => :kes,
413
+ :kg => :kgs,
414
+ :kgz => :kgs,
415
+ :kh => :khr,
416
+ :khm => :khr,
417
+ :ki => :aud,
418
+ :kir => :aud,
419
+ :km => :kmf,
420
+ :kn => :xcd,
421
+ :kna => :xcd,
422
+ :kor => :krw,
423
+ :kp => :kpw,
424
+ :kr => :krw,
425
+ :kw => :kwd,
426
+ :kwt => :kwd,
427
+ :ky => :kyd,
428
+ :kz => :kzt,
429
+ :la => :lak,
430
+ :lao => :lak,
431
+ :lb => :lbp,
432
+ :lbn => :lbp,
433
+ :lbr => :lrd,
434
+ :lby => :lyd,
435
+ :lc => :xcd,
436
+ :lca => :xcd,
437
+ :li => :chf,
438
+ :lie => :chf,
439
+ :lk => :lkr,
440
+ :lka => :lkr,
441
+ :lr => :lrd,
442
+ :ls => :zar,
443
+ :lso => :zar,
444
+ :lt => :ltl,
445
+ :ltu => :ltl,
446
+ :lu => :eur,
447
+ :lux => :eur,
448
+ :lv => :lvl,
449
+ :lva => :lvl,
450
+ :ly => :lyd,
451
+ :ma => :mad,
452
+ :mac => :mop,
453
+ :maf => :eur,
454
+ :mar => :mad,
455
+ :mc => :eur,
456
+ :mco => :eur,
457
+ :md => :mdl,
458
+ :mda => :mdl,
459
+ :mdg => :mga,
460
+ :mdv => :mvr,
461
+ :me => :eur,
462
+ :mex => :mxn,
463
+ :mf => :eur,
464
+ :mg => :mga,
465
+ :mh => :usd,
466
+ :mhl => :usd,
467
+ :mk => :mkd,
468
+ :mkd => :mkd,
469
+ :ml => :xof,
470
+ :mli => :xof,
471
+ :mlt => :eur,
472
+ :mm => :mmk,
473
+ :mmr => :mmk,
474
+ :mn => :mnt,
475
+ :mne => :eur,
476
+ :mng => :mnt,
477
+ :mnp => :usd,
478
+ :mo => :mop,
479
+ :moz => :mzn,
480
+ :mp => :usd,
481
+ :mq => :eur,
482
+ :mr => :mro,
483
+ :mrt => :mro,
484
+ :ms => :xcd,
485
+ :msr => :xcd,
486
+ :mt => :eur,
487
+ :mtq => :eur,
488
+ :mu => :mur,
489
+ :mus => :mur,
490
+ :mv => :mvr,
491
+ :mw => :mwk,
492
+ :mwi => :mwk,
493
+ :mx => :mxn,
494
+ :my => :myr,
495
+ :mys => :myr,
496
+ :myt => :eur,
497
+ :mz => :mzn,
498
+ :na => :zar,
499
+ :nam => :zar,
500
+ :nc => :xpf,
501
+ :ncl => :xpf,
502
+ :ne => :xof,
503
+ :ner => :xof,
504
+ :nf => :aud,
505
+ :nfk => :aud,
506
+ :ng => :ngn,
507
+ :nga => :ngn,
508
+ :ni => :nio,
509
+ :nic => :nio,
510
+ :niu => :nzd,
511
+ :nl => :eur,
512
+ :nld => :eur,
513
+ :no => :nok,
514
+ :nor => :nok,
515
+ :np => :npr,
516
+ :npl => :npr,
517
+ :nr => :aud,
518
+ :nru => :aud,
519
+ :nu => :nzd,
520
+ :nz => :nzd,
521
+ :nzl => :nzd,
522
+ :om => :omr,
523
+ :omn => :omr,
524
+ :pa => :usd,
525
+ :pak => :pkr,
526
+ :pan => :usd,
527
+ :pcn => :nzd,
528
+ :pe => :pen,
529
+ :per => :pen,
530
+ :pf => :xpf,
531
+ :pg => :pgk,
532
+ :ph => :php,
533
+ :phl => :php,
534
+ :pk => :pkr,
535
+ :pl => :pln,
536
+ :plw => :usd,
537
+ :pm => :eur,
538
+ :pn => :nzd,
539
+ :png => :pgk,
540
+ :pol => :pln,
541
+ :pr => :usd,
542
+ :pri => :usd,
543
+ :prk => :kpw,
544
+ :prt => :eur,
545
+ :pry => :pyg,
546
+ :pt => :eur,
547
+ :pw => :usd,
548
+ :py => :pyg,
549
+ :pyf => :xpf,
550
+ :qa => :qar,
551
+ :qat => :qar,
552
+ :re => :eur,
553
+ :reu => :eur,
554
+ :ro => :ron,
555
+ :rou => :ron,
556
+ :rs => :rsd,
557
+ :ru => :rub,
558
+ :rus => :rub,
559
+ :rw => :rwf,
560
+ :rwa => :rwf,
561
+ :sa => :sar,
562
+ :sau => :sar,
563
+ :sb => :sbd,
564
+ :sc => :scr,
565
+ :sd => :sdg,
566
+ :sdn => :sdg,
567
+ :se => :sek,
568
+ :sen => :xof,
569
+ :sg => :sgd,
570
+ :sgp => :sgd,
571
+ :sh => :shp,
572
+ :shn => :shp,
573
+ :si => :eur,
574
+ :sj => :nok,
575
+ :sjm => :nok,
576
+ :sk => :eur,
577
+ :sl => :sll,
578
+ :slb => :sbd,
579
+ :sle => :sll,
580
+ :slv => :usd,
581
+ :sm => :eur,
582
+ :smr => :eur,
583
+ :sn => :xof,
584
+ :so => :sos,
585
+ :som => :sos,
586
+ :spm => :eur,
587
+ :sr => :srd,
588
+ :srb => :rsd,
589
+ :ss => :ssp,
590
+ :ssd => :ssp,
591
+ :st => :std,
592
+ :stp => :std,
593
+ :sur => :srd,
594
+ :sv => :usd,
595
+ :svk => :eur,
596
+ :svn => :eur,
597
+ :swe => :sek,
598
+ :swz => :szl,
599
+ :sx => :ang,
600
+ :sxm => :ang,
601
+ :sy => :syp,
602
+ :syc => :scr,
603
+ :syr => :syp,
604
+ :sz => :szl,
605
+ :tc => :usd,
606
+ :tca => :usd,
607
+ :tcd => :xaf,
608
+ :td => :xaf,
609
+ :tf => :eur,
610
+ :tg => :xof,
611
+ :tgo => :xof,
612
+ :th => :thb,
613
+ :tha => :thb,
614
+ :tj => :tjs,
615
+ :tjk => :tjs,
616
+ :tk => :nzd,
617
+ :tkl => :nzd,
618
+ :tkm => :tmt,
619
+ :tl => :usd,
620
+ :tls => :usd,
621
+ :tm => :tmt,
622
+ :tn => :tnd,
623
+ :to => :top,
624
+ :ton => :top,
625
+ :tr => :try,
626
+ :tt => :ttd,
627
+ :tto => :ttd,
628
+ :tun => :tnd,
629
+ :tur => :try,
630
+ :tuv => :aud,
631
+ :tv => :aud,
632
+ :tw => :twd,
633
+ :twn => :twd,
634
+ :tz => :tzs,
635
+ :tza => :tzs,
636
+ :ua => :uah,
637
+ :ug => :ugx,
638
+ :uga => :ugx,
639
+ :ukr => :uah,
640
+ :um => :usd,
641
+ :umi => :usd,
642
+ :ury => :uyu,
643
+ :us => :usd,
644
+ :usa => :usd,
645
+ :uy => :uyu,
646
+ :uz => :uzs,
647
+ :uzb => :uzs,
648
+ :va => :eur,
649
+ :vat => :eur,
650
+ :vc => :xcd,
651
+ :vct => :xcd,
652
+ :ve => :vef,
653
+ :ven => :vef,
654
+ :vg => :usd,
655
+ :vgb => :usd,
656
+ :vi => :usd,
657
+ :vir => :usd,
658
+ :vn => :vnd,
659
+ :vnm => :vnd,
660
+ :vu => :vuv,
661
+ :vut => :vuv,
662
+ :wf => :xpf,
663
+ :wlf => :xpf,
664
+ :ws => :wst,
665
+ :wsm => :wst,
666
+ :ye => :yer,
667
+ :yem => :yer,
668
+ :yt => :eur,
669
+ :za => :zar,
670
+ :zaf => :zar,
671
+ :zm => :zmk,
672
+ :zmb => :zmk,
673
+ :zw => :zwl,
674
+ :zwe => :zwl
675
+ }
676
+ end
677
+ end
678
+ describe "self.currencies" do
679
+ it "should be an array of currency symbols" do
680
+ 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 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)
681
+ end
682
+ end
683
+ describe "self.defines?" do
684
+ context "with a defined currency" do
685
+ it "should return true" do
686
+ subject.currencies.each do |curr|
687
+ subject.should be_defines(curr)
688
+ end
689
+ end
690
+ end
691
+ context "with a defined country" do
692
+ it "should return true" do
693
+ subject.country_map.each do |country, currency|
694
+ subject.should be_defines(country)
695
+ end
696
+ end
697
+ end
698
+ context "with an undefined currency" do
699
+ it "should return false" do
700
+ subject.should_not be_defines(:xxx)
701
+ end
702
+ end
703
+ end
704
+ describe "self.assert_currency" do
705
+ context "with a currency" do
706
+ it "should return the currency itself" do
707
+ subject.assert_currency!(:eur).should == :eur
708
+ end
709
+ end
710
+ context "with a country" do
711
+ it "should return the matching currency for the country" do
712
+ subject.assert_currency!(:de).should == :eur
713
+ end
714
+ end
715
+ context "with a non-currency" do
716
+ it "should raise an error" do
717
+ lambda { subject.assert_currency!(:xxx) }.should raise_error(Exchange::NoCurrencyError, "xxx is not a currency nor a country code matchable to a currency")
718
+ end
719
+ end
720
+ end
721
+ describe "self.instantiate" do
722
+ context "given a float or an integer" do
723
+ context "with bigger precision than the definition" do
724
+ it "should instantiate a big decimal with the given precision" do
725
+ BigDecimal.should_receive(:new).with('23.2345', 6).and_return('INSTANCE')
726
+ subject.instantiate(23.2345, :tnd).should == 'INSTANCE'
727
+ BigDecimal.should_receive(:new).with('22223.2323444', 12).and_return('INSTANCE')
728
+ subject.instantiate(22223.2323444, :sar).should == 'INSTANCE'
729
+ BigDecimal.should_receive(:new).with('23.23', 4).and_return('INSTANCE')
730
+ subject.instantiate(23.23, :clp).should == 'INSTANCE'
731
+ end
732
+ end
733
+ context "with smaller precision than the definition" do
734
+ it "should instantiate a big decimal with the defined precision" do
735
+ BigDecimal.should_receive(:new).with('23382343.1',11).and_return('INSTANCE')
736
+ subject.instantiate(23382343.1, :tnd).should == 'INSTANCE'
737
+ BigDecimal.should_receive(:new).with('23',4).and_return('INSTANCE')
738
+ subject.instantiate(23, :sar).should == 'INSTANCE'
739
+ BigDecimal.should_receive(:new).with('23.2',5).and_return('INSTANCE')
740
+ subject.instantiate(23.2, :omr).should == 'INSTANCE'
741
+ end
742
+ end
743
+ end
744
+ context "given a big decimal" do
745
+ let!(:bigdecimal) { BigDecimal.new("23.23") }
746
+ it "should instantiate a big decimal according to the iso standards" do
747
+ BigDecimal.should_receive(:new).never
748
+ subject.instantiate(bigdecimal, :tnd).should == bigdecimal
749
+ end
750
+ end
751
+ end
752
+ describe "self.round" do
753
+ it "should round a currency according to ISO 4217 Definitions" do
754
+ subject.round(BigDecimal.new("23.232524"), :tnd).should == BigDecimal.new("23.233")
755
+ subject.round(BigDecimal.new("23.232524"), :sar).should == BigDecimal.new("23.23")
756
+ subject.round(BigDecimal.new("23.232524"), :clp).should == BigDecimal.new("23")
757
+ end
758
+ end
759
+ describe "self.stringify" do
760
+ it "should stringify a currency according to ISO 4217 Definitions" do
761
+ subject.stringify(BigDecimal.new("23.232524"), :tnd).should == "TND 23.233"
762
+ subject.stringify(BigDecimal.new("23.232524"), :sar).should == "SAR 23.23"
763
+ subject.stringify(BigDecimal.new("23.232524"), :clp).should == "CLP 23"
764
+ subject.stringify(BigDecimal.new("23.2"), :tnd).should == "TND 23.200"
765
+ subject.stringify(BigDecimal.new("23.4"), :sar).should == "SAR 23.40"
766
+ subject.stringify(BigDecimal.new("23.0"), :clp).should == "CLP 23"
767
+ end
768
+ context "amount only" do
769
+ it "should not render the currency" do
770
+ subject.stringify(BigDecimal.new("23.232524"), :tnd, :amount_only => true).should == "23.233"
771
+ subject.stringify(BigDecimal.new("23.232524"), :sar, :amount_only => true).should == "23.23"
772
+ subject.stringify(BigDecimal.new("23.232524"), :clp, :amount_only => true).should == "23"
773
+ subject.stringify(BigDecimal.new("23.2"), :tnd, :amount_only => true).should == "23.200"
774
+ subject.stringify(BigDecimal.new("23.4"), :sar, :amount_only => true).should == "23.40"
775
+ subject.stringify(BigDecimal.new("23.0"), :clp, :amount_only => true).should == "23"
776
+ end
777
+ end
778
+ context "symbol" do
779
+ context "with a symbol present" do
780
+ it "should render a symbol for the currency" do
781
+ subject.stringify(BigDecimal.new("23.232524"), :usd, :symbol => true).should == "$23.23"
782
+ subject.stringify(BigDecimal.new("23.232524"), :irr, :symbol => true).should == "﷼23.23"
783
+ subject.stringify(BigDecimal.new("23.232524"), :gbp, :symbol => true).should == "£23.23"
784
+ subject.stringify(BigDecimal.new("23.232524"), :eur, :symbol => true).should == "€23.23"
785
+ end
786
+ end
787
+ context "without a symbol present" do
788
+ it "should render the currency abbreviation" do
789
+ subject.stringify(BigDecimal.new("23.232524"), :chf, :symbol => true).should == "CHF23.23"
790
+ subject.stringify(BigDecimal.new("23.232524"), :etb, :symbol => true).should == "ETB23.23"
791
+ end
792
+ end
793
+ end
794
+ end
795
+ end