timsjoberg-ecriso4217 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.rdoc +29 -0
- data/Rakefile +21 -0
- data/lib/iso4217.rb +4 -0
- data/lib/iso4217/currencies.rb +181 -0
- data/lib/iso4217/currency.rb +19 -0
- data/lib/iso4217/iso4217.rb +266 -0
- data/lib/iso4217/version.rb +3 -0
- data/spec/currencies_spec.rb +24 -0
- data/spec/currency_spec.rb +23 -0
- data/spec/iso4217_spec.rb +323 -0
- data/spec/spec_helper.rb +9 -0
- data/timsjoberg-ecriso4217.gemspec +26 -0
- metadata +149 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Enrique Comba Riepenhausen
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
= ISO4217
|
2
|
+
|
3
|
+
(extract from Wikipedia)
|
4
|
+
|
5
|
+
ISO 4217 is the international standard describing three-letter codes
|
6
|
+
(also known as the currency code) to define the names of currencies
|
7
|
+
established by the International Organization for Standardization (ISO).
|
8
|
+
The ISO 4217 code list is the established norm in banking and business
|
9
|
+
all over the world for defining different currencies, and in many countries
|
10
|
+
the codes for the more common currencies are so well known publicly, that
|
11
|
+
exchange rates published in newspapers or posted in banks use only these
|
12
|
+
to define the different currencies, instead of translated currency names
|
13
|
+
or ambiguous currency symbols. ISO 4217 codes are used on airline tickets
|
14
|
+
and international train tickets to remove any ambiguity about the price.
|
15
|
+
|
16
|
+
== Note on Patches/Pull Requests
|
17
|
+
|
18
|
+
* Fork the project.
|
19
|
+
* Make your feature addition or bug fix.
|
20
|
+
* Add tests for it. This is important so I don't break it in a
|
21
|
+
future version unintentionally.
|
22
|
+
* Commit, do not mess with rakefile, version, or history.
|
23
|
+
(if you want to have your own version, that is fine but
|
24
|
+
bump version in a commit by itself I can ignore when I pull)
|
25
|
+
* Send me a pull request. Bonus points for topic branches.
|
26
|
+
|
27
|
+
== Copyright
|
28
|
+
|
29
|
+
Copyright (c) 2009 Enrique Comba Riepenhausen. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
include Rake::DSL
|
2
|
+
|
3
|
+
require 'bundler'
|
4
|
+
Bundler::GemHelper.install_tasks
|
5
|
+
|
6
|
+
require "rspec/core/rake_task"
|
7
|
+
desc "Run specs"
|
8
|
+
RSpec::Core::RakeTask.new do |t|
|
9
|
+
t.rspec_opts = %w(-fs --color)
|
10
|
+
# t.ruby_opts = %w(-w)
|
11
|
+
end
|
12
|
+
|
13
|
+
task :default => :spec
|
14
|
+
|
15
|
+
require 'rdoc/task'
|
16
|
+
Rake::RDocTask.new do |rdoc|
|
17
|
+
rdoc.rdoc_dir = 'rdoc'
|
18
|
+
rdoc.title = "ecriso4217 #{ISO4217::VERSION}"
|
19
|
+
rdoc.rdoc_files.include('README*')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
data/lib/iso4217.rb
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
module ISO4217
|
2
|
+
|
3
|
+
GENERIC_CURRENCY_SIGN= "U+00a4"
|
4
|
+
DOLLAR_SIGN= "U+0024"
|
5
|
+
POUND_SIGN= "U+00a3"
|
6
|
+
|
7
|
+
CURRENCIES = [
|
8
|
+
UNITED_ARAB_EMIRATES_DIRHAM = Currency.new(:AED, 'د.إ', 'United Arab Emirates Dirham'),
|
9
|
+
AFGHAN_AFGHANI = Currency.new(:AFN, '؋', 'Afghan Afghani'),
|
10
|
+
ALBANIAN_LEK = Currency.new(:ALL, 'L', 'Albanian Lek'),
|
11
|
+
ARMENIAN_DRAM = Currency.new(:AMD, 'դր.', 'Armenian Dram'),
|
12
|
+
NETHERLANDS_ANTILLEAN_GULDEN = Currency.new(:ANG, 'ƒ', 'Netherlands Antillean Gulden'),
|
13
|
+
ANGOLAN_KWANZA = Currency.new(:AOA, 'Kz', 'Angolan Kwanza'),
|
14
|
+
ARGENTINE_PESO = Currency.new(:ARS, '$', 'Argentine Peso'),
|
15
|
+
AUSTRALIAN_DOLLAR = Currency.new(:AUD, '$', 'Australian Dollar'),
|
16
|
+
ARUBAN_FLORIN = Currency.new(:AWG, 'ƒ', 'Aruban Florin'),
|
17
|
+
AZERBAIJANI_MANAT = Currency.new(:AZN, 'man', 'Azerbaijani Manat'),
|
18
|
+
BOSNIA_AND_HERZEGOVINA_CONVERTIBLE_MARK = Currency.new(:BAM, 'KM', 'Bosnia and Herzegovina Convertible Mark'),
|
19
|
+
BARBADIAN_DOLLAR = Currency.new(:BBD, '$', 'Barbadian Dollar'),
|
20
|
+
BANGLADESHI_TAKA = Currency.new(:BDT, '৳', 'Bangladeshi Taka'),
|
21
|
+
BULGARIAN_LEV = Currency.new(:BGN, 'лв', 'Bulgarian Lev'),
|
22
|
+
BAHRAINI_DINAR = Currency.new(:BHD, 'ب.د', 'Bahraini Dinar'),
|
23
|
+
BURUNDIAN_FRANC = Currency.new(:BIF, 'Fr', 'Burundian Franc'),
|
24
|
+
BERMUDIAN_DOLLAR = Currency.new(:BMD, '$', 'Bermudian Dollar'),
|
25
|
+
BRUNEI_DOLLAR = Currency.new(:BND, '$', 'Brunei Dollar'),
|
26
|
+
BOLIVIAN_BOLIVIANO = Currency.new(:BOB, 'Bs.', 'Bolivian Boliviano'),
|
27
|
+
BRAZILIAN_REAL = Currency.new(:BRL, 'R$ ', 'Brazilian Real'),
|
28
|
+
BAHAMIAN_DOLLAR = Currency.new(:BSD, '$', 'Bahamian Dollar'),
|
29
|
+
BHUTANESE_NGULTRUM = Currency.new(:BTN, 'Nu', 'Bhutanese Ngultrum'),
|
30
|
+
BOTSWANA_PULA = Currency.new(:BWP, 'P', 'Botswana Pula'),
|
31
|
+
BELARUSIAN_RUBLE = Currency.new(:BYR, 'Br', 'Belarusian Ruble'),
|
32
|
+
BELIZE_DOLLAR = Currency.new(:BZD, '$', 'Belize Dollar'),
|
33
|
+
CANADIAN_DOLLAR = Currency.new(:CAD, 'Can$', 'Canadian Dollar'),
|
34
|
+
CONGOLESE_FRANC = Currency.new(:CDF, 'Fr', 'Congolese Franc'),
|
35
|
+
SWISS_FRANC = Currency.new(:CHF, 'Fr', 'Swiss Franc'),
|
36
|
+
CHILEAN_PESO = Currency.new(:CLP, '$', 'Chilean Peso'),
|
37
|
+
CHINESE_RENMINBI_YUAN = Currency.new(:CNY, '¥', 'Chinese Renminbi Yuan'),
|
38
|
+
COLOMBIAN_PESO = Currency.new(:COP, '$', 'Colombian Peso'),
|
39
|
+
COSTA_RICAN_COLON = Currency.new(:CRC, '₡', 'Costa Rican Colón'),
|
40
|
+
CUBAN_CONVERTIBLE_PESO = Currency.new(:CUC, '$', 'Cuban Convertible Peso'),
|
41
|
+
CUBAN_PESO = Currency.new(:CUP, '$', 'Cuban Peso'),
|
42
|
+
CAPE_VERDEAN_ESCUDO = Currency.new(:CVE, 'Esc', 'Cape Verdean Escudo'),
|
43
|
+
CZECH_KORUNA = Currency.new(:CZK, 'Kč', 'Czech Koruna'),
|
44
|
+
DJIBOUTIAN_FRANC = Currency.new(:DJF, 'Fr', 'Djiboutian Franc'),
|
45
|
+
DANISH_KRONE = Currency.new(:DKK, 'kr', 'Danish Krone'),
|
46
|
+
DOMINICAN_PESO = Currency.new(:DOP, '$', 'Dominican Peso'),
|
47
|
+
ALGERIAN_DINAR = Currency.new(:DZD, 'د.ج', 'Algerian Dinar'),
|
48
|
+
ESTONIAN_KROON = Currency.new(:EEK, 'KR', 'Estonian Kroon'),
|
49
|
+
EGYPTIAN_POUND = Currency.new(:EGP, 'ج.م', 'Egyptian Pound'),
|
50
|
+
ERITREAN_NAKFA = Currency.new(:ERN, 'Nfk', 'Eritrean Nakfa'),
|
51
|
+
ETHIOPIAN_BIRR = Currency.new(:ETB, 'Br', 'Ethiopian Birr'),
|
52
|
+
EURO = Currency.new(:EUR, '€', 'Euro'),
|
53
|
+
FIJIAN_DOLLAR = Currency.new(:FJD, '$', 'Fijian Dollar'),
|
54
|
+
FALKLAND_POUND = Currency.new(:FKP, '£', 'Falkland Pound'),
|
55
|
+
BRITISH_POUND = Currency.new(:GBP, '£', 'Pound Sterling'),
|
56
|
+
GEORGIAN_LARI = Currency.new(:GEL, 'ლ', 'Georgian Lari'),
|
57
|
+
GHANAIAN_CEDI = Currency.new(:GHS, '₵', 'Ghanaian Cedi'),
|
58
|
+
GIBRALTAR_POUND = Currency.new(:GIP, '£', 'Gibraltar Pound'),
|
59
|
+
GAMBIAN_DALASI = Currency.new(:GMD, 'D', 'Gambian Dalasi'),
|
60
|
+
GUINEAN_FRANC = Currency.new(:GNF, 'Fr', 'Guinean Franc'),
|
61
|
+
GUATEMALAN_QUETZAL = Currency.new(:GTQ, 'Q', 'Guatemalan Quetzal'),
|
62
|
+
GUYANESE_DOLLAR = Currency.new(:GYD, '$', 'Guyanese Dollar'),
|
63
|
+
HONG_KONG_DOLLAR = Currency.new(:HKD, '$', 'Hong Kong Dollar'),
|
64
|
+
HONDURAN_LEMPIRA = Currency.new(:HNL, 'L', 'Honduran Lempira'),
|
65
|
+
CROATIAN_KUNA = Currency.new(:HRK, 'kn', 'Croatian Kuna'),
|
66
|
+
HAITIAN_GOURDE = Currency.new(:HTG, 'G', 'Haitian Gourde'),
|
67
|
+
HUNGARIAN_FORINT = Currency.new(:HUF, 'Ft', 'Hungarian Forint'),
|
68
|
+
INDONESIAN_RUPIAH = Currency.new(:IDR, 'Rp', 'Indonesian Rupiah'),
|
69
|
+
ISRAELI_NEW_SHEQEL = Currency.new(:ILS, '₪', 'Israeli New Sheqel'),
|
70
|
+
INDIAN_RUPEE = Currency.new(:INR, '₨', 'Indian Rupee'),
|
71
|
+
IRAQI_DINAR = Currency.new(:IQD, 'ع.د', 'Iraqi Dinar'),
|
72
|
+
IRANIAN_RIAL = Currency.new(:IRR, '﷼', 'Iranian Rial'),
|
73
|
+
ICELANDIC_KRONA = Currency.new(:ISK, 'kr', 'Icelandic Króna'),
|
74
|
+
JAMAICAN_DOLLAR = Currency.new(:JMD, '$', 'Jamaican Dollar'),
|
75
|
+
JORDANIAN_DINAR = Currency.new(:JOD, 'د.ا', 'Jordanian Dinar'),
|
76
|
+
JAPANESE_YEN = Currency.new(:JPY, '¥', 'Japanese Yen'),
|
77
|
+
KENYAN_SHILLING = Currency.new(:KES, 'Sh', 'Kenyan Shilling'),
|
78
|
+
KYRGYZSTANI_SOM = Currency.new(:KGS, '', 'Kyrgyzstani Som'),
|
79
|
+
CAMBODIAN_RIEL = Currency.new(:KHR, '៛', 'Cambodian Riel'),
|
80
|
+
COMORIAN_FRANC = Currency.new(:KMF, 'Fr', 'Comorian Franc'),
|
81
|
+
NORTH_KOREAN_WON = Currency.new(:KPW, '₩', 'North Korean Won'),
|
82
|
+
SOUTH_KOREAN_WON = Currency.new(:KRW, '₩', 'South Korean Won'),
|
83
|
+
KUWAITI_DINAR = Currency.new(:KWD, 'د.ك', 'Kuwaiti Dinar'),
|
84
|
+
CAYMAN_ISLANDS_DOLLAR = Currency.new(:KYD, '$', 'Cayman Islands Dollar'),
|
85
|
+
KAZAKHSTANI_TENGE = Currency.new(:KZT, '〒', 'Kazakhstani Tenge'),
|
86
|
+
LAO_KIP = Currency.new(:LAK, '₭', 'Lao Kip'),
|
87
|
+
LEBANESE_LIRA = Currency.new(:LBP, 'ل.ل', 'Lebanese Lira'),
|
88
|
+
SRI_LANKAN_RUPEE = Currency.new(:LKR, '₨', 'Sri Lankan Rupee'),
|
89
|
+
LIBERIAN_DOLLAR = Currency.new(:LRD, '$', 'Liberian Dollar'),
|
90
|
+
LESOTHO_LOTI = Currency.new(:LSL, 'L', 'Lesotho Loti'),
|
91
|
+
LITHUANIAN_LITAS = Currency.new(:LTL, 'Lt', 'Lithuanian Litas'),
|
92
|
+
LATVIAN_LATS = Currency.new(:LVL, 'Ls', 'Latvian Lats'),
|
93
|
+
LIBYAN_DINAR = Currency.new(:LYD, 'ل.د', 'Libyan Dinar'),
|
94
|
+
MOROCCAN_DIRHAM = Currency.new(:MAD, 'د.م.', 'Moroccan Dirham'),
|
95
|
+
MOLDOVAN_LEU = Currency.new(:MDL, 'L', 'Moldovan Leu'),
|
96
|
+
MALAGASY_ARIARY = Currency.new(:MGA, '', 'Malagasy Ariary'),
|
97
|
+
MACEDONIAN_DENAR = Currency.new(:MKD, 'ден', 'Macedonian Denar'),
|
98
|
+
MYANMAR_KYAT = Currency.new(:MMK, 'K', 'Myanmar Kyat'),
|
99
|
+
MONGOLIAN_TOGROG = Currency.new(:MNT, '₮', 'Mongolian Tögrög'),
|
100
|
+
MACANESE_PATACA = Currency.new(:MOP, 'P', 'Macanese Pataca'),
|
101
|
+
MAURITANIAN_OUGUIYA = Currency.new(:MRO, 'UM', 'Mauritanian Ouguiya'),
|
102
|
+
MAURITIAN_RUPEE = Currency.new(:MUR, '₨', 'Mauritian Rupee'),
|
103
|
+
MALDIVIAN_RUFIYAA = Currency.new(:MVR, 'ރ.', 'Maldivian Rufiyaa'),
|
104
|
+
MALAWIAN_KWACHA = Currency.new(:MWK, 'MK', 'Malawian Kwacha'),
|
105
|
+
MEXICAN_PESO = Currency.new(:MXN, '$', 'Mexican Peso'),
|
106
|
+
MALAYSIAN_RINGGIT = Currency.new(:MYR, 'RM', 'Malaysian Ringgit'),
|
107
|
+
MOZAMBICAN_METICAL = Currency.new(:MZN, 'MTn', 'Mozambican Metical'),
|
108
|
+
NAMIBIAN_DOLLAR = Currency.new(:NAD, '$', 'Namibian Dollar'),
|
109
|
+
NIGERIAN_NAIRA = Currency.new(:NGN, '₦', 'Nigerian Naira'),
|
110
|
+
NICARAGUAN_CORDOBA = Currency.new(:NIO, 'C$', 'Nicaraguan Córdoba'),
|
111
|
+
NORWEGIAN_KRONE = Currency.new(:NOK, 'kr', 'Norwegian Krone'),
|
112
|
+
NEPALESE_RUPEE = Currency.new(:NPR, '₨', 'Nepalese Rupee'),
|
113
|
+
NEW_ZEALAND_DOLLAR = Currency.new(:NZD, '$', 'New Zealand Dollar'),
|
114
|
+
OMANI_RIAL = Currency.new(:OMR, 'ر.ع.', 'Omani Rial'),
|
115
|
+
PANAMANIAN_BALBOA = Currency.new(:PAB, 'B/.', 'Panamanian Balboa'),
|
116
|
+
PERUVIAN_NUEVO_SOL = Currency.new(:PEN, 'S/.', 'Peruvian Nuevo Sol'),
|
117
|
+
PAPUA_NEW_GUINEAN_KINA = Currency.new(:PGK, 'K', 'Papua New Guinean Kina'),
|
118
|
+
PHILIPPINE_PESO = Currency.new(:PHP, '₱', 'Philippine Peso'),
|
119
|
+
PAKISTANI_RUPEE = Currency.new(:PKR, '₨', 'Pakistani Rupee'),
|
120
|
+
POLISH_ZLOTY = Currency.new(:PLN, 'zł', 'Polish Złoty'),
|
121
|
+
PARAGUAYAN_GUARANI = Currency.new(:PYG, '₲', 'Paraguayan Guaraní'),
|
122
|
+
QATARI_RIYAL = Currency.new(:QAR, 'ر.ق', 'Qatari Riyal'),
|
123
|
+
ROMANIAN_LEU = Currency.new(:RON, 'L', 'Romanian Leu'),
|
124
|
+
SERBIAN_DINAR = Currency.new(:RSD, 'дин.', 'Serbian Dinar'),
|
125
|
+
RUSSIAN_RUBLE = Currency.new(:RUB, 'руб.', 'Russian Ruble'),
|
126
|
+
RWANDAN_FRANC = Currency.new(:RWF, 'Fr', 'Rwandan Franc'),
|
127
|
+
SAUDI_RIYAL = Currency.new(:SAR, 'ر.س', 'Saudi Riyal'),
|
128
|
+
SOLOMON_ISLANDS_DOLLAR = Currency.new(:SBD, '$', 'Solomon Islands Dollar'),
|
129
|
+
SEYCHELLOIS_RUPEE = Currency.new(:SCR, '₨', 'Seychellois Rupee'),
|
130
|
+
SUDANESE_POUND = Currency.new(:SDG, '£', 'Sudanese Pound'),
|
131
|
+
SWEDISH_KRONA = Currency.new(:SEK, 'kr', 'Swedish Krona'),
|
132
|
+
SINGAPORE_DOLLAR = Currency.new(:SGD, '$', 'Singapore Dollar'),
|
133
|
+
SAINT_HELENIAN_POUND = Currency.new(:SHP, '£', 'Saint Helenian Pound'),
|
134
|
+
SLOVAK_KORUNA = Currency.new(:SKK, 'Sk', 'Slovak Koruna'),
|
135
|
+
SIERRA_LEONEAN_LEONE = Currency.new(:SLL, 'Le', 'Sierra Leonean Leone'),
|
136
|
+
SOMALI_SHILLING = Currency.new(:SOS, 'Sh', 'Somali Shilling'),
|
137
|
+
SURINAMESE_DOLLAR = Currency.new(:SRD, '$', 'Surinamese Dollar'),
|
138
|
+
SAO_TOME_AND_PRINCIPE_DOBRA = Currency.new(:STD, 'Db', 'São Tomé and Príncipe Dobra'),
|
139
|
+
SALVADORAN_COLON = Currency.new(:SVC, '₡', 'Salvadoran Colón'),
|
140
|
+
SYRIAN_POUND = Currency.new(:SYP, 'ل.س', 'Syrian Pound'),
|
141
|
+
SWAZI_LILANGENI = Currency.new(:SZL, 'L', 'Swazi Lilangeni'),
|
142
|
+
THAI_BAHT = Currency.new(:THB, '฿', 'Thai Baht'),
|
143
|
+
TAJIKISTANI_SOMONI = Currency.new(:TJS, 'ЅМ', 'Tajikistani Somoni'),
|
144
|
+
TURKMENISTANI_MANAT = Currency.new(:TMM, 'm', 'Turkmenistani Manat'),
|
145
|
+
TUNISIAN_DINAR = Currency.new(:TND, 'د.ت', 'Tunisian Dinar'),
|
146
|
+
TONGAN_PAANGA = Currency.new(:TOP, 'T$', 'Tongan Paʻanga'),
|
147
|
+
TURKISH_NEW_LIRA = Currency.new(:TRY, 'TL', 'Turkish New Lira'),
|
148
|
+
TRINIDAD_AND_TOBAGO_DOLLAR = Currency.new(:TTD, '$', 'Trinidad and Tobago Dollar'),
|
149
|
+
NEW_TAIWAN_DOLLAR = Currency.new(:TWD, '$', 'New Taiwan Dollar'),
|
150
|
+
TANZANIAN_SHILLING = Currency.new(:TZS, 'Sh', 'Tanzanian Shilling'),
|
151
|
+
UKRAINIAN_HRYVNIA = Currency.new(:UAH, '₴', 'Ukrainian Hryvnia'),
|
152
|
+
UGANDAN_SHILLING = Currency.new(:UGX, 'Sh', 'Ugandan Shilling'),
|
153
|
+
UNITED_STATES_DOLLAR = Currency.new(:USD, '$', 'US Dollar'),
|
154
|
+
URUGUAYAN_PESO = Currency.new(:UYU, '$', 'Uruguayan Peso'),
|
155
|
+
UZBEKISTANI_SOM = Currency.new(:UZS, '', 'Uzbekistani Som'),
|
156
|
+
VENEZUELAN_BOLIVAR = Currency.new(:VEF, 'Bs F', 'Venezuelan Bolívar'),
|
157
|
+
VIETNAMESE_DONG = Currency.new(:VND, '₫', 'Vietnamese Đồng'),
|
158
|
+
VANUATU_VATU = Currency.new(:VUV, 'Vt', 'Vanuatu Vatu'),
|
159
|
+
SAMOAN_TALA = Currency.new(:WST, 'T', 'Samoan Tala'),
|
160
|
+
CENTRAL_AFRICAN_CFA_FRANC = Currency.new(:XAF, 'Fr', 'Central African Cfa Franc'),
|
161
|
+
EAST_CARIBBEAN_DOLLAR = Currency.new(:XCD, '$', 'East Caribbean Dollar'),
|
162
|
+
WEST_AFRICAN_CFA_FRANC = Currency.new(:XOF, 'Fr', 'West African Cfa Franc'),
|
163
|
+
CFP_FRANC = Currency.new(:XPF, 'Fr', 'Cfp Franc'),
|
164
|
+
YEMENI_RIAL = Currency.new(:YER, '﷼', 'Yemeni Rial'),
|
165
|
+
SOUTH_AFRICAN_RAND = Currency.new(:ZAR, 'R', 'South African Rand'),
|
166
|
+
ZAMBIAN_KWACHA = Currency.new(:ZMK, 'ZK', 'Zambian Kwacha'),
|
167
|
+
ZIMBABWEAN_DOLLAR = Currency.new(:ZWD, '$', 'Zimbabwean Dollar')
|
168
|
+
]
|
169
|
+
|
170
|
+
CURRENCY_BY_CODE = Hash.new
|
171
|
+
|
172
|
+
CURRENCIES.each do |currency|
|
173
|
+
CURRENCY_BY_CODE[currency.code.to_s]= currency
|
174
|
+
end
|
175
|
+
|
176
|
+
module CurrencyHelper
|
177
|
+
def currency(code)
|
178
|
+
CURRENCY_BY_CODE[code.to_s]
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ISO4217
|
2
|
+
class Currency
|
3
|
+
attr_reader :code, :sign, :name
|
4
|
+
|
5
|
+
def initialize(code, sign, name)
|
6
|
+
@code, @sign, @name = code, utf8(sign), name
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_s
|
10
|
+
"Code: #{@code} | Sign: #{@sign} | Currency: #{@name}"
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def utf8(string)
|
15
|
+
string.gsub(/U\+([0-9a-fA-F]{4,4})/u){["#$1".hex ].pack('U*')}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,266 @@
|
|
1
|
+
module ISO4217
|
2
|
+
module CurrencyHelper
|
3
|
+
|
4
|
+
COUNTRIES = {
|
5
|
+
:AF => AFGHAN_AFGHANI,
|
6
|
+
:AX => EURO,
|
7
|
+
:AL => ALBANIAN_LEK,
|
8
|
+
:DZ => ALGERIAN_DINAR,
|
9
|
+
:AS => UNITED_STATES_DOLLAR,
|
10
|
+
:AD => EURO,
|
11
|
+
:AO => ANGOLAN_KWANZA,
|
12
|
+
:AI => EAST_CARIBBEAN_DOLLAR,
|
13
|
+
:AG => EAST_CARIBBEAN_DOLLAR,
|
14
|
+
:AR => ARGENTINE_PESO,
|
15
|
+
:AM => ARMENIAN_DRAM,
|
16
|
+
:AW => ARUBAN_FLORIN,
|
17
|
+
:AU => AUSTRALIAN_DOLLAR,
|
18
|
+
:AT => EURO,
|
19
|
+
:AZ => AZERBAIJANI_MANAT,
|
20
|
+
:BS => BAHAMIAN_DOLLAR,
|
21
|
+
:BH => BAHRAINI_DINAR,
|
22
|
+
:BD => BANGLADESHI_TAKA,
|
23
|
+
:BB => BARBADIAN_DOLLAR,
|
24
|
+
:BY => BELARUSIAN_RUBLE,
|
25
|
+
:BE => EURO,
|
26
|
+
:BZ => BELIZE_DOLLAR,
|
27
|
+
:BJ => WEST_AFRICAN_CFA_FRANC,
|
28
|
+
:BM => BERMUDIAN_DOLLAR,
|
29
|
+
:BT => INDIAN_RUPEE,
|
30
|
+
:BO => BOLIVIAN_BOLIVIANO,
|
31
|
+
:BA => BOSNIA_AND_HERZEGOVINA_CONVERTIBLE_MARK,
|
32
|
+
:BW => BOTSWANA_PULA,
|
33
|
+
:BV => NORWEGIAN_KRONE,
|
34
|
+
:BR => BRAZILIAN_REAL,
|
35
|
+
:IO => UNITED_STATES_DOLLAR,
|
36
|
+
:BN => BRUNEI_DOLLAR,
|
37
|
+
:BG => BULGARIAN_LEV,
|
38
|
+
:BF => WEST_AFRICAN_CFA_FRANC,
|
39
|
+
:BI => BURUNDIAN_FRANC,
|
40
|
+
:KH => CAMBODIAN_RIEL,
|
41
|
+
:CM => CENTRAL_AFRICAN_CFA_FRANC,
|
42
|
+
:CA => CANADIAN_DOLLAR,
|
43
|
+
:CV => CAPE_VERDEAN_ESCUDO,
|
44
|
+
:KY => CAYMAN_ISLANDS_DOLLAR,
|
45
|
+
:CF => CENTRAL_AFRICAN_CFA_FRANC,
|
46
|
+
:TD => CENTRAL_AFRICAN_CFA_FRANC,
|
47
|
+
:CL => CHILEAN_PESO,
|
48
|
+
:CN => CHINESE_RENMINBI_YUAN,
|
49
|
+
:CX => AUSTRALIAN_DOLLAR,
|
50
|
+
:CC => AUSTRALIAN_DOLLAR,
|
51
|
+
:CO => COLOMBIAN_PESO,
|
52
|
+
:KM => COMORIAN_FRANC,
|
53
|
+
:CG => CENTRAL_AFRICAN_CFA_FRANC,
|
54
|
+
:CD => CONGOLESE_FRANC,
|
55
|
+
:CK => NEW_ZEALAND_DOLLAR,
|
56
|
+
:CR => COSTA_RICAN_COLON,
|
57
|
+
:CI => WEST_AFRICAN_CFA_FRANC,
|
58
|
+
:HR => CROATIAN_KUNA,
|
59
|
+
:CU => CUBAN_PESO,
|
60
|
+
:CY => EURO,
|
61
|
+
:CZ => CZECH_KORUNA,
|
62
|
+
:DK => DANISH_KRONE,
|
63
|
+
:DJ => DJIBOUTIAN_FRANC,
|
64
|
+
:DM => EAST_CARIBBEAN_DOLLAR,
|
65
|
+
:DO => DOMINICAN_PESO,
|
66
|
+
:EC => UNITED_STATES_DOLLAR,
|
67
|
+
:EG => EGYPTIAN_POUND,
|
68
|
+
:SV => SALVADORAN_COLON,
|
69
|
+
:GQ => CENTRAL_AFRICAN_CFA_FRANC,
|
70
|
+
:ER => ERITREAN_NAKFA,
|
71
|
+
:EE => ESTONIAN_KROON,
|
72
|
+
:ET => ETHIOPIAN_BIRR,
|
73
|
+
:FK => FALKLAND_POUND,
|
74
|
+
:FO => DANISH_KRONE,
|
75
|
+
:FJ => FIJIAN_DOLLAR,
|
76
|
+
:FI => EURO,
|
77
|
+
:FR => EURO,
|
78
|
+
:GF => EURO,
|
79
|
+
:PF => CFP_FRANC,
|
80
|
+
:TF => EURO,
|
81
|
+
:GA => CENTRAL_AFRICAN_CFA_FRANC,
|
82
|
+
:GM => GAMBIAN_DALASI,
|
83
|
+
:GE => GEORGIAN_LARI,
|
84
|
+
:DE => EURO,
|
85
|
+
:GH => GHANAIAN_CEDI,
|
86
|
+
:GI => GIBRALTAR_POUND,
|
87
|
+
:GR => EURO,
|
88
|
+
:GL => DANISH_KRONE,
|
89
|
+
:GD => EAST_CARIBBEAN_DOLLAR,
|
90
|
+
:GP => EURO,
|
91
|
+
:GU => UNITED_STATES_DOLLAR,
|
92
|
+
:GT => GUATEMALAN_QUETZAL,
|
93
|
+
:GG => BRITISH_POUND,
|
94
|
+
:GN => GUINEAN_FRANC,
|
95
|
+
:GW => WEST_AFRICAN_CFA_FRANC,
|
96
|
+
:GY => GUYANESE_DOLLAR,
|
97
|
+
:HT => HAITIAN_GOURDE,
|
98
|
+
:HM => AUSTRALIAN_DOLLAR,
|
99
|
+
:VA => EURO,
|
100
|
+
:HN => HONDURAN_LEMPIRA,
|
101
|
+
:HK => HONG_KONG_DOLLAR,
|
102
|
+
:HU => HUNGARIAN_FORINT,
|
103
|
+
:IS => ICELANDIC_KRONA,
|
104
|
+
:IN => INDIAN_RUPEE,
|
105
|
+
:ID => INDONESIAN_RUPIAH,
|
106
|
+
:IR => IRANIAN_RIAL,
|
107
|
+
:IQ => IRAQI_DINAR,
|
108
|
+
:IE => EURO,
|
109
|
+
:IM => BRITISH_POUND,
|
110
|
+
:IL => ISRAELI_NEW_SHEQEL,
|
111
|
+
:IT => EURO,
|
112
|
+
:JM => JAMAICAN_DOLLAR,
|
113
|
+
:JP => JAPANESE_YEN,
|
114
|
+
:JE => BRITISH_POUND,
|
115
|
+
:JO => JORDANIAN_DINAR,
|
116
|
+
:KZ => KAZAKHSTANI_TENGE,
|
117
|
+
:KE => KENYAN_SHILLING,
|
118
|
+
:KI => AUSTRALIAN_DOLLAR,
|
119
|
+
:KP => NORTH_KOREAN_WON,
|
120
|
+
:KR => SOUTH_KOREAN_WON,
|
121
|
+
:KW => KUWAITI_DINAR,
|
122
|
+
:KG => KYRGYZSTANI_SOM,
|
123
|
+
:LA => LAO_KIP,
|
124
|
+
:LV => LATVIAN_LATS,
|
125
|
+
:LB => LEBANESE_LIRA,
|
126
|
+
:LS => SOUTH_AFRICAN_RAND,
|
127
|
+
:LR => LIBERIAN_DOLLAR,
|
128
|
+
:LY => LIBYAN_DINAR,
|
129
|
+
:LI => SWISS_FRANC,
|
130
|
+
:LT => LITHUANIAN_LITAS,
|
131
|
+
:LU => EURO,
|
132
|
+
:MO => MACANESE_PATACA,
|
133
|
+
:MK => MACEDONIAN_DENAR,
|
134
|
+
:MG => MALAGASY_ARIARY,
|
135
|
+
:MW => MALAWIAN_KWACHA,
|
136
|
+
:MY => MALAYSIAN_RINGGIT,
|
137
|
+
:MV => MALDIVIAN_RUFIYAA,
|
138
|
+
:ML => WEST_AFRICAN_CFA_FRANC,
|
139
|
+
:MT => EURO,
|
140
|
+
:MH => UNITED_STATES_DOLLAR,
|
141
|
+
:MQ => EURO,
|
142
|
+
:MR => MAURITANIAN_OUGUIYA,
|
143
|
+
:MU => MAURITIAN_RUPEE,
|
144
|
+
:YT => EURO,
|
145
|
+
:MX => MEXICAN_PESO,
|
146
|
+
:FM => UNITED_STATES_DOLLAR,
|
147
|
+
:MD => MOLDOVAN_LEU,
|
148
|
+
:MC => EURO,
|
149
|
+
:MN => MONGOLIAN_TOGROG,
|
150
|
+
:ME => EURO,
|
151
|
+
:MS => EAST_CARIBBEAN_DOLLAR,
|
152
|
+
:MA => MOROCCAN_DIRHAM,
|
153
|
+
:MZ => MOZAMBICAN_METICAL,
|
154
|
+
:MM => MYANMAR_KYAT,
|
155
|
+
:NA => SOUTH_AFRICAN_RAND,
|
156
|
+
:NR => AUSTRALIAN_DOLLAR,
|
157
|
+
:NP => NEPALESE_RUPEE,
|
158
|
+
:NL => EURO,
|
159
|
+
:AN => NETHERLANDS_ANTILLEAN_GULDEN,
|
160
|
+
:NC => CFP_FRANC,
|
161
|
+
:NZ => NEW_ZEALAND_DOLLAR,
|
162
|
+
:NI => NICARAGUAN_CORDOBA,
|
163
|
+
:NE => WEST_AFRICAN_CFA_FRANC,
|
164
|
+
:NG => NIGERIAN_NAIRA,
|
165
|
+
:NU => NEW_ZEALAND_DOLLAR,
|
166
|
+
:NF => AUSTRALIAN_DOLLAR,
|
167
|
+
:MP => UNITED_STATES_DOLLAR,
|
168
|
+
:NO => NORWEGIAN_KRONE,
|
169
|
+
:OM => OMANI_RIAL,
|
170
|
+
:PK => PAKISTANI_RUPEE,
|
171
|
+
:PW => UNITED_STATES_DOLLAR,
|
172
|
+
:PS => UNITED_STATES_DOLLAR,
|
173
|
+
:PA => PANAMANIAN_BALBOA,
|
174
|
+
:PG => PAPUA_NEW_GUINEAN_KINA,
|
175
|
+
:PY => PARAGUAYAN_GUARANI,
|
176
|
+
:PE => PERUVIAN_NUEVO_SOL,
|
177
|
+
:PH => PHILIPPINE_PESO,
|
178
|
+
:PN => NEW_ZEALAND_DOLLAR,
|
179
|
+
:PL => POLISH_ZLOTY,
|
180
|
+
:PT => EURO,
|
181
|
+
:PR => UNITED_STATES_DOLLAR,
|
182
|
+
:QA => QATARI_RIYAL,
|
183
|
+
:RE => EURO,
|
184
|
+
:RO => ROMANIAN_LEU,
|
185
|
+
:RU => RUSSIAN_RUBLE,
|
186
|
+
:RW => RWANDAN_FRANC,
|
187
|
+
:BL => RWANDAN_FRANC,
|
188
|
+
:SH => RWANDAN_FRANC,
|
189
|
+
:KN => EAST_CARIBBEAN_DOLLAR,
|
190
|
+
:LC => EAST_CARIBBEAN_DOLLAR,
|
191
|
+
:MF => EURO,
|
192
|
+
:PM => EURO,
|
193
|
+
:VC => EAST_CARIBBEAN_DOLLAR,
|
194
|
+
:WS => SAMOAN_TALA,
|
195
|
+
:SM => EURO,
|
196
|
+
:ST => EURO,
|
197
|
+
:SA => SAUDI_RIYAL,
|
198
|
+
:SN => WEST_AFRICAN_CFA_FRANC,
|
199
|
+
:RS => SERBIAN_DINAR,
|
200
|
+
:SC => SEYCHELLOIS_RUPEE,
|
201
|
+
:SL => SIERRA_LEONEAN_LEONE,
|
202
|
+
:SG => SINGAPORE_DOLLAR,
|
203
|
+
:SK => EURO,
|
204
|
+
:SI => EURO,
|
205
|
+
:SB => SOLOMON_ISLANDS_DOLLAR,
|
206
|
+
:SO => SOMALI_SHILLING,
|
207
|
+
:ZA => SOUTH_AFRICAN_RAND,
|
208
|
+
:GS => SOUTH_AFRICAN_RAND,
|
209
|
+
:ES => EURO,
|
210
|
+
:LK => SRI_LANKAN_RUPEE,
|
211
|
+
:SD => SUDANESE_POUND,
|
212
|
+
:SR => SURINAMESE_DOLLAR,
|
213
|
+
:SJ => NORWEGIAN_KRONE,
|
214
|
+
:SZ => SWAZI_LILANGENI,
|
215
|
+
:SE => SWEDISH_KRONA,
|
216
|
+
:CH => SWISS_FRANC,
|
217
|
+
:SY => SYRIAN_POUND,
|
218
|
+
:TW => NEW_TAIWAN_DOLLAR,
|
219
|
+
:TJ => TAJIKISTANI_SOMONI,
|
220
|
+
:TZ => TANZANIAN_SHILLING,
|
221
|
+
:TH => THAI_BAHT,
|
222
|
+
:TL => UNITED_STATES_DOLLAR,
|
223
|
+
:TG => WEST_AFRICAN_CFA_FRANC,
|
224
|
+
:TK => NEW_ZEALAND_DOLLAR,
|
225
|
+
:TO => TONGAN_PAANGA,
|
226
|
+
:TT => TRINIDAD_AND_TOBAGO_DOLLAR,
|
227
|
+
:TN => TUNISIAN_DINAR,
|
228
|
+
:TR => TURKISH_NEW_LIRA,
|
229
|
+
:TM => TURKMENISTANI_MANAT,
|
230
|
+
:TC => UNITED_STATES_DOLLAR,
|
231
|
+
:TV => AUSTRALIAN_DOLLAR,
|
232
|
+
:UG => UGANDAN_SHILLING,
|
233
|
+
:UA => UKRAINIAN_HRYVNIA,
|
234
|
+
:AE => UNITED_ARAB_EMIRATES_DIRHAM,
|
235
|
+
:GB => BRITISH_POUND,
|
236
|
+
:UK => BRITISH_POUND,
|
237
|
+
:US => UNITED_STATES_DOLLAR,
|
238
|
+
:UM => UNITED_STATES_DOLLAR,
|
239
|
+
:UY => URUGUAYAN_PESO,
|
240
|
+
:UZ => UZBEKISTANI_SOM,
|
241
|
+
:VU => VANUATU_VATU,
|
242
|
+
:VE => VENEZUELAN_BOLIVAR,
|
243
|
+
:VN => VIETNAMESE_DONG,
|
244
|
+
:VG => UNITED_STATES_DOLLAR,
|
245
|
+
:VI => UNITED_STATES_DOLLAR,
|
246
|
+
:WF => CFP_FRANC,
|
247
|
+
:EH => MOROCCAN_DIRHAM,
|
248
|
+
:YE => YEMENI_RIAL,
|
249
|
+
:ZM => ZAMBIAN_KWACHA,
|
250
|
+
:ZW => ZIMBABWEAN_DOLLAR
|
251
|
+
}
|
252
|
+
|
253
|
+
def currency_for(country_code, default_when_currency_not_found= :NAC)
|
254
|
+
COUNTRIES[country_code] || Currency.new(default_when_currency_not_found, GENERIC_CURRENCY_SIGN, 'unknown')
|
255
|
+
end
|
256
|
+
|
257
|
+
def currency_code_for(country_code, default_when_currency_not_found= :NAC)
|
258
|
+
currency_for(country_code, default_when_currency_not_found).code.to_s
|
259
|
+
end
|
260
|
+
|
261
|
+
def currency_sign_for(country_code, default_when_currency_not_found= :NAC)
|
262
|
+
currency_for(country_code, default_when_currency_not_found).sign
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Currencies" do
|
4
|
+
include ISO4217::CurrencyHelper
|
5
|
+
|
6
|
+
context "when searching for a currency" do
|
7
|
+
it "returns the british pound" do
|
8
|
+
currency(:GBP).should == ISO4217::BRITISH_POUND
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns the United States dollar" do
|
12
|
+
currency(:USD).should == ISO4217::UNITED_STATES_DOLLAR
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns the Euro" do
|
16
|
+
currency(:EUR).should == ISO4217::EURO
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns the Cayman Islands dollar" do
|
20
|
+
currency(:KYD).should == ISO4217::CAYMAN_ISLANDS_DOLLAR
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe ISO4217::Currency do
|
4
|
+
|
5
|
+
context "creation" do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@currency = ISO4217::Currency.new(:EUR, 'U+20ac', 'euro')
|
9
|
+
end
|
10
|
+
|
11
|
+
it "has a code assigned to it" do
|
12
|
+
@currency.code.should == :EUR
|
13
|
+
end
|
14
|
+
|
15
|
+
it "has a sign" do
|
16
|
+
@currency.sign.should == '€'
|
17
|
+
end
|
18
|
+
|
19
|
+
it "has a name" do
|
20
|
+
@currency.name.should == 'euro'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,323 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe ISO4217 do
|
4
|
+
|
5
|
+
include ISO4217::CurrencyHelper
|
6
|
+
|
7
|
+
EURO_COUNTRIES = [:AD, :AT, :BE, :CY, :DE, :IE, :ES, :FR, :IT, :LU,
|
8
|
+
:MT, :NL, :PT, :SI, :SK, :FI, :GR, :MC, :ME, :SM, :SI]
|
9
|
+
|
10
|
+
context "finding currency codes for known countries" do
|
11
|
+
it "returns the currency euro code of the countries in the euro zone" do
|
12
|
+
EURO_COUNTRIES.each do |country|
|
13
|
+
currency_code_for(country).should == 'EUR'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns the currency code for the United Kingdom" do
|
18
|
+
currency_code_for(:UK).should == 'GBP'
|
19
|
+
currency_code_for(:GB).should == 'GBP'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns the currency code for United States of America" do
|
23
|
+
currency_code_for(:US).should == 'USD'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns the currency code for Canada" do
|
27
|
+
currency_code_for(:CA).should == 'CAD'
|
28
|
+
end
|
29
|
+
|
30
|
+
it "returns the currency code for Afghanistan" do
|
31
|
+
currency_code_for(:AF).should == 'AFN'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "returns the currency code for Albania" do
|
35
|
+
currency_code_for(:AL).should == 'ALL'
|
36
|
+
end
|
37
|
+
|
38
|
+
it "returns the currency code for Algeria" do
|
39
|
+
currency_code_for(:DZ).should == 'DZD'
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns the currency code for American Samoa" do
|
43
|
+
currency_code_for(:AS).should == 'USD'
|
44
|
+
end
|
45
|
+
|
46
|
+
it "returns the currency code for Angola" do
|
47
|
+
currency_code_for(:AO).should == 'AOA'
|
48
|
+
end
|
49
|
+
|
50
|
+
it "returns the currency code for Anguilla" do
|
51
|
+
currency_code_for(:AI).should == 'XCD'
|
52
|
+
end
|
53
|
+
|
54
|
+
it "returns the currency code for Antigua and Barbuda" do
|
55
|
+
currency_code_for(:AG).should == 'XCD'
|
56
|
+
end
|
57
|
+
|
58
|
+
it "returns the currency code for Argentina" do
|
59
|
+
currency_code_for(:AR).should == 'ARS'
|
60
|
+
end
|
61
|
+
|
62
|
+
it "returns the currency code for Armenia" do
|
63
|
+
currency_code_for(:AM).should == 'AMD'
|
64
|
+
end
|
65
|
+
|
66
|
+
it "returns the currency code for Aruba" do
|
67
|
+
currency_code_for(:AW).should == 'AWG'
|
68
|
+
end
|
69
|
+
|
70
|
+
it "returns the currency code for Australia" do
|
71
|
+
currency_code_for(:AU).should == 'AUD'
|
72
|
+
end
|
73
|
+
|
74
|
+
it "returns the currency code for Azerbaijan" do
|
75
|
+
currency_code_for(:AZ).should == 'AZN'
|
76
|
+
end
|
77
|
+
|
78
|
+
it "returns the currency code for Bahamas" do
|
79
|
+
currency_code_for(:BS).should == 'BSD'
|
80
|
+
end
|
81
|
+
|
82
|
+
it "returns the currency code for Bulgaria" do
|
83
|
+
currency_code_for(:BG).should == 'BGN'
|
84
|
+
end
|
85
|
+
|
86
|
+
it "returns the currency code for Bahrain" do
|
87
|
+
currency_code_for(:BH).should == 'BHD'
|
88
|
+
end
|
89
|
+
|
90
|
+
it "returns the currency code for Bangladesh" do
|
91
|
+
currency_code_for(:BD).should == 'BDT'
|
92
|
+
end
|
93
|
+
|
94
|
+
it "returns the currency code for Barbados" do
|
95
|
+
currency_code_for(:BB).should == 'BBD'
|
96
|
+
end
|
97
|
+
|
98
|
+
it "returns the currency code for Czech Republic" do
|
99
|
+
currency_code_for(:CZ).should == 'CZK'
|
100
|
+
end
|
101
|
+
|
102
|
+
it "returns the currency code for Denmark" do
|
103
|
+
currency_code_for(:DK).should == 'DKK'
|
104
|
+
end
|
105
|
+
|
106
|
+
it "returns the currency code for Estonia" do
|
107
|
+
currency_code_for(:EE).should == 'EEK'
|
108
|
+
end
|
109
|
+
|
110
|
+
it "returns the currency code for Latvia" do
|
111
|
+
currency_code_for(:LV).should == 'LVL'
|
112
|
+
end
|
113
|
+
|
114
|
+
it "returns the currency code for Lithuania" do
|
115
|
+
currency_code_for(:LT).should == 'LTL'
|
116
|
+
end
|
117
|
+
|
118
|
+
it "returns the currency code for Hungary" do
|
119
|
+
currency_code_for(:HU).should == 'HUF'
|
120
|
+
end
|
121
|
+
|
122
|
+
it "returns the currency code for Poland" do
|
123
|
+
currency_code_for(:PL).should == 'PLN'
|
124
|
+
end
|
125
|
+
|
126
|
+
it "returns the currency code for Romania" do
|
127
|
+
currency_code_for(:RO).should == 'RON'
|
128
|
+
end
|
129
|
+
|
130
|
+
it "returns the currency code for Sweden" do
|
131
|
+
currency_code_for(:SE).should == 'SEK'
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
context "finding currency codes of unknown countries" do
|
137
|
+
|
138
|
+
it "returns 'unknown' if it doesn't know the currency" do
|
139
|
+
currency_code_for(:MARS).should == 'NAC'
|
140
|
+
end
|
141
|
+
|
142
|
+
it "returns the requested default currency code if it doesn't know the currency" do
|
143
|
+
currency_code_for(:MARS, 'GBP').should == 'GBP'
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context "prints the sign of known currencies" do
|
148
|
+
it "returns the euro sign for the countries in the euro zone" do
|
149
|
+
EURO_COUNTRIES.each do |country|
|
150
|
+
currency_sign_for(country).should == '€'
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
it "returns the dollar sign for the American dollar" do
|
155
|
+
currency_sign_for(:US).should == '$'
|
156
|
+
end
|
157
|
+
|
158
|
+
it "returns the canadian dollar sign for canadian dollars" do
|
159
|
+
currency_sign_for(:CA).should == "Can$"
|
160
|
+
end
|
161
|
+
|
162
|
+
it "returns the Afghan Afghani sign for Afghanistan" do
|
163
|
+
currency_sign_for(:AF).should == "؋"
|
164
|
+
end
|
165
|
+
|
166
|
+
it "returns the Albanian Lek sign for Albania" do
|
167
|
+
currency_sign_for(:AL).should == "L"
|
168
|
+
end
|
169
|
+
|
170
|
+
it "returns the Algerian Dinar sign for Algeria" do
|
171
|
+
currency_sign_for(:DZ).should == "د.ج"
|
172
|
+
end
|
173
|
+
|
174
|
+
it "returns the dollar sign for American Samoa" do
|
175
|
+
currency_sign_for(:AS).should == "$"
|
176
|
+
end
|
177
|
+
|
178
|
+
it "returns the Kwanza sign for Angolan kwanza" do
|
179
|
+
currency_sign_for(:AO).should == "Kz"
|
180
|
+
end
|
181
|
+
|
182
|
+
it "returns the East Carribean Dollar sign for Anguilla" do
|
183
|
+
currency_sign_for(:AI).should == "$"
|
184
|
+
end
|
185
|
+
|
186
|
+
it "returns the East Carribean Dollar sign for Antigua and Barbuda" do
|
187
|
+
currency_sign_for(:AG).should == "$"
|
188
|
+
end
|
189
|
+
|
190
|
+
it "returns the Argentine Peso sign for Argentina" do
|
191
|
+
currency_sign_for(:AR).should == "$"
|
192
|
+
end
|
193
|
+
|
194
|
+
it "returns the Armenian dram sign for Armenia" do
|
195
|
+
currency_sign_for(:AM).should == "դր."
|
196
|
+
end
|
197
|
+
|
198
|
+
it "returns the Aruban florin sign for Aruba" do
|
199
|
+
currency_sign_for(:AW).should == "ƒ"
|
200
|
+
end
|
201
|
+
|
202
|
+
it "returns the Australian dollar sign for Australia" do
|
203
|
+
currency_sign_for(:AU).should == "$"
|
204
|
+
end
|
205
|
+
|
206
|
+
it "returns the Azerbaijan manat sign for Azerbaijan" do
|
207
|
+
currency_sign_for(:AZ).should == "man"
|
208
|
+
end
|
209
|
+
|
210
|
+
it "returns the Bahamian dollar sign for Bahamas" do
|
211
|
+
currency_sign_for(:BS).should == "$"
|
212
|
+
end
|
213
|
+
|
214
|
+
it "returns the Bahraini dinar sign for Bahrain" do
|
215
|
+
currency_sign_for(:BH).should == "ب.د"
|
216
|
+
end
|
217
|
+
|
218
|
+
it "returns the Bangladeshi taka sign for Bangladesh" do
|
219
|
+
currency_sign_for(:BD).should == "৳"
|
220
|
+
end
|
221
|
+
|
222
|
+
it "returns the Barbados dollar sign for Barbados" do
|
223
|
+
currency_sign_for(:BB).should == "$"
|
224
|
+
end
|
225
|
+
|
226
|
+
end
|
227
|
+
|
228
|
+
context "prints the sign for unknown currency" do
|
229
|
+
it "returns the generic currency sign for unknown currencies" do
|
230
|
+
currency_sign_for(:MARS).should == "¤"
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
context "currencies of known countries" do
|
235
|
+
it "returns the currency object for Euro if searching for currencies in the euro zone" do
|
236
|
+
EURO_COUNTRIES.each do |country|
|
237
|
+
currency_for(country).should == ISO4217::EURO
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
it "returns the currency object for GBP when searching for the currency in Great Britain" do
|
242
|
+
[:GB, :UK].each {|country| currency_for(country).should == ISO4217::BRITISH_POUND}
|
243
|
+
end
|
244
|
+
|
245
|
+
it "returns the currency object for the dollar if searching for the American currency" do
|
246
|
+
currency_for(:US).should == ISO4217::UNITED_STATES_DOLLAR
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
context "name of a currency" do
|
251
|
+
it "returns the (human readable) name of the euro" do
|
252
|
+
ISO4217::EURO.name.should == 'Euro'
|
253
|
+
end
|
254
|
+
|
255
|
+
it "returns the (human readable) name of the Canadian dollar" do
|
256
|
+
currency_for(:CA).name.should == 'Canadian Dollar'
|
257
|
+
end
|
258
|
+
|
259
|
+
it "returns the (human readable) name of the pound sterling" do
|
260
|
+
ISO4217::BRITISH_POUND.name.should == 'Pound Sterling'
|
261
|
+
end
|
262
|
+
|
263
|
+
it "returns the (human readable) name of the US dollar" do
|
264
|
+
ISO4217::UNITED_STATES_DOLLAR.name.should == 'US Dollar'
|
265
|
+
end
|
266
|
+
|
267
|
+
it "returns the (human readable) name of the Afghani" do
|
268
|
+
ISO4217::AFGHAN_AFGHANI.name.should == 'Afghan Afghani'
|
269
|
+
end
|
270
|
+
|
271
|
+
it "returns the (human readable) name of the Albanian Lek" do
|
272
|
+
ISO4217::ALBANIAN_LEK.name.should == 'Albanian Lek'
|
273
|
+
end
|
274
|
+
|
275
|
+
it "returns the (human readable) name of the Algerian Dinar" do
|
276
|
+
ISO4217::ALGERIAN_DINAR.name.should == 'Algerian Dinar'
|
277
|
+
end
|
278
|
+
|
279
|
+
it "returns the (human readable) name of the Angolan kwanza" do
|
280
|
+
ISO4217::ANGOLAN_KWANZA.name.should == 'Angolan Kwanza'
|
281
|
+
end
|
282
|
+
|
283
|
+
it "returns the (human readable) name of the Armenian dram" do
|
284
|
+
ISO4217::ARMENIAN_DRAM.name.should == 'Armenian Dram'
|
285
|
+
end
|
286
|
+
|
287
|
+
it "returns the (human readable) name of the Aruban florin" do
|
288
|
+
ISO4217::ARUBAN_FLORIN.name.should == 'Aruban Florin'
|
289
|
+
end
|
290
|
+
|
291
|
+
it "returns the (human readable) name of the Australian dollar" do
|
292
|
+
ISO4217::AUSTRALIAN_DOLLAR.name.should == 'Australian Dollar'
|
293
|
+
end
|
294
|
+
|
295
|
+
it "returns the (human readable) name of the Azerbaijan manat" do
|
296
|
+
ISO4217::AZERBAIJANI_MANAT.name.should == 'Azerbaijani Manat'
|
297
|
+
end
|
298
|
+
|
299
|
+
it "returns the (human readable) name of the Bahamian dollar" do
|
300
|
+
ISO4217::BAHAMIAN_DOLLAR.name.should == 'Bahamian Dollar'
|
301
|
+
end
|
302
|
+
|
303
|
+
it "returns the (human readable) name of the Bahraini dinar" do
|
304
|
+
ISO4217::BAHRAINI_DINAR.name.should == 'Bahraini Dinar'
|
305
|
+
end
|
306
|
+
|
307
|
+
it "returns the (human readable) name of the Bangladeshi taka" do
|
308
|
+
ISO4217::BANGLADESHI_TAKA.name.should == 'Bangladeshi Taka'
|
309
|
+
end
|
310
|
+
|
311
|
+
it "returns the (human readable) name of the Barbados dollar" do
|
312
|
+
ISO4217::BARBADIAN_DOLLAR.name.should == 'Barbadian Dollar'
|
313
|
+
end
|
314
|
+
|
315
|
+
end
|
316
|
+
|
317
|
+
context "printing a curency object" do
|
318
|
+
it "prints the currency object for the EURO" do
|
319
|
+
ISO4217::EURO.to_s.should == "Code: EUR | Sign: € | Currency: Euro"
|
320
|
+
end
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "iso4217/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "timsjoberg-ecriso4217"
|
7
|
+
s.version = ISO4217::VERSION
|
8
|
+
s.authors = ["Enrique Comba Riepenhausen"]
|
9
|
+
s.email = ["ecomba@nexwerk.com"]
|
10
|
+
s.homepage = "https://github.com/timsjoberg/ecriso4217"
|
11
|
+
s.summary = "Currencies as described by the ISO 4217 Standard"
|
12
|
+
s.description = "When dealing with currencies in code you don't need to roll up your own interpretation of a currency. Now you can just use the ISO 4217 gem to work with them."
|
13
|
+
|
14
|
+
s.rubyforge_project = "timsjoberg-ecriso4217"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_development_dependency "rspec"
|
22
|
+
s.add_development_dependency "bundler"
|
23
|
+
s.add_development_dependency "rake"
|
24
|
+
s.add_development_dependency "rdoc"
|
25
|
+
s.add_development_dependency "rdoc-data"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: timsjoberg-ecriso4217
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 7
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 6
|
9
|
+
- 0
|
10
|
+
version: 0.6.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Enrique Comba Riepenhausen
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-10-12 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
prerelease: false
|
22
|
+
name: rspec
|
23
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :development
|
33
|
+
requirement: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
prerelease: false
|
36
|
+
name: bundler
|
37
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
type: :development
|
47
|
+
requirement: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
prerelease: false
|
50
|
+
name: rake
|
51
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
type: :development
|
61
|
+
requirement: *id003
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
prerelease: false
|
64
|
+
name: rdoc
|
65
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
type: :development
|
75
|
+
requirement: *id004
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
prerelease: false
|
78
|
+
name: rdoc-data
|
79
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
type: :development
|
89
|
+
requirement: *id005
|
90
|
+
description: When dealing with currencies in code you don't need to roll up your own interpretation of a currency. Now you can just use the ISO 4217 gem to work with them.
|
91
|
+
email:
|
92
|
+
- ecomba@nexwerk.com
|
93
|
+
executables: []
|
94
|
+
|
95
|
+
extensions: []
|
96
|
+
|
97
|
+
extra_rdoc_files: []
|
98
|
+
|
99
|
+
files:
|
100
|
+
- .gitignore
|
101
|
+
- Gemfile
|
102
|
+
- LICENSE
|
103
|
+
- README.rdoc
|
104
|
+
- Rakefile
|
105
|
+
- lib/iso4217.rb
|
106
|
+
- lib/iso4217/currencies.rb
|
107
|
+
- lib/iso4217/currency.rb
|
108
|
+
- lib/iso4217/iso4217.rb
|
109
|
+
- lib/iso4217/version.rb
|
110
|
+
- spec/currencies_spec.rb
|
111
|
+
- spec/currency_spec.rb
|
112
|
+
- spec/iso4217_spec.rb
|
113
|
+
- spec/spec_helper.rb
|
114
|
+
- timsjoberg-ecriso4217.gemspec
|
115
|
+
homepage: https://github.com/timsjoberg/ecriso4217
|
116
|
+
licenses: []
|
117
|
+
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
hash: 3
|
129
|
+
segments:
|
130
|
+
- 0
|
131
|
+
version: "0"
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
none: false
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
hash: 3
|
138
|
+
segments:
|
139
|
+
- 0
|
140
|
+
version: "0"
|
141
|
+
requirements: []
|
142
|
+
|
143
|
+
rubyforge_project: timsjoberg-ecriso4217
|
144
|
+
rubygems_version: 1.8.6
|
145
|
+
signing_key:
|
146
|
+
specification_version: 3
|
147
|
+
summary: Currencies as described by the ISO 4217 Standard
|
148
|
+
test_files: []
|
149
|
+
|