iso_3166 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .idea
4
+ .rbx
5
+ .bundle
6
+ .config
7
+ .yardoc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in iso_3166.gemspec
4
+ gemspec
5
+
6
+ gem "unicode_utils"
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 real.sergeych@gmail.com
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # Iso3166
2
+
3
+ Gem provides country data according to ISO 3166 as OpenStruct object that
4
+ holds country name, number, A2 and A3 codes, and aliases if any. These objects
5
+ are global and shared, so you can add your own fields you might find useful.
6
+
7
+ Currently only few national names and aliases are added, you can add an issue
8
+ here https://github.com/sergeych/iso_countries/issues or just fork and add it
9
+ yourself.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'iso_3166'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install iso_3166
24
+
25
+ ## Usage
26
+
27
+
28
+ To get country data from name use either its ISO
29
+
30
+ 1.9.3-p327 :003 > require 'iso_3166'
31
+ => true
32
+ 1.9.3-p327 :004 > Iso3166.for_name 'Australia'
33
+ => #<OpenStruct name="AUSTRALIA", code2="AU", code3="AUS", number=36>
34
+ 1.9.3-p327 :012 > Iso3166.for_name 'United Kingdom'
35
+ => #<OpenStruct name="UNITED KINGDOM", code2="GB", code3="GBR", number=826, name_aliases=["UNITED KINGDOM*", "Great Britain", "England"]>
36
+ 1.9.3-p327 :013 > 1.9.3-p327 :013 > Iso3166.for_name 'Great Britain'
37
+ => #<OpenStruct name="UNITED KINGDOM", code2="GB", code3="GBR", number=826, name_aliases=["UNITED KINGDOM*", "Great Britain", "England"]>
38
+
39
+ You can easily add your own alias:
40
+
41
+ 1.9.3-p327 :002 > Iso3166.for_name('Oz') # No such country
42
+ => nil
43
+
44
+ Add it with add_alias. First argument is 2 or 3-letter country code, then the desired name:
45
+
46
+ 1.9.3-p327 :003 > Iso3166.add_alias 'AU', 'oz'
47
+ => #<OpenStruct name="AUSTRALIA", code2="AU", code3="AUS", number=36, name_aliases=["oz"]>
48
+ 1.9.3-p327 :004 > Iso3166.for_name('Oz')
49
+ => #<OpenStruct name="AUSTRALIA", code2="AU", code3="AUS", number=36, name_aliases=["oz"]>
50
+ 1.9.3-p327 :005 >
51
+
52
+ To retrieve country information from its 2 or 3-letter code:
53
+
54
+ 1.9.3-p327 :005 > Iso3166.for_code 'RUS'
55
+ => #<OpenStruct name="RUSSIAN FEDERATION", code2="RU", code3="RUS", number=643, name_aliases=["Россия", "РФ", "Russia"]>
56
+ 1.9.3-p327 :006 > Iso3166.for_code 'US'
57
+ => #<OpenStruct name="UNITED STATES", code2="US", code3="USA", number=840, name_aliases=["USA", "США"]>
58
+ 1.9.3-p327 :006 > Iso3166.for_code 'USA'
59
+ => #<OpenStruct name="UNITED STATES", code2="US", code3="USA", number=840, name_aliases=["USA", "США"]>
60
+
61
+ ###
62
+ ## Contributing
63
+
64
+ 1. Fork it
65
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
66
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
67
+ 4. Push to the branch (`git push origin my-new-feature`)
68
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'iso_3166/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "iso_3166"
8
+ gem.version = Iso3166::VERSION
9
+ gem.authors = ["sergeych"]
10
+ gem.email = ["real.sergeych@gmail.com"]
11
+ gem.description = "Utility class to deal with ISO3166 country codes, names and number"
12
+ gem.summary = ""
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency "rspec"
21
+ end
data/lib/iso_3166.rb ADDED
@@ -0,0 +1,669 @@
1
+ # encoding: utf-8
2
+ require "iso_3166/version"
3
+ require "unicode_utils/upcase"
4
+
5
+ module Iso3166
6
+
7
+ #
8
+ # Iso3166 countries standard utility class
9
+ # (C) 2010 Sergey S. Chernov, Trhift, RU
10
+ #
11
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ # of this software and associated documentation files (the "Software"), to
13
+ # deal in the Software without restriction, including without limitation the
14
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
15
+ # sell copies of the Software, and to permit persons to whom the Software is
16
+ # furnished to do so, subject to the following conditions:
17
+ #
18
+ # The above copyright notice and this permission notice shall be included in
19
+ # all copies or substantial portions of the Software.
20
+ #
21
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27
+ # IN THE SOFTWARE.
28
+
29
+ require 'ostruct'
30
+
31
+ class Coder
32
+ class <<self
33
+ # Return ISO3166 data for a given country name, which is case insensitive
34
+ # but should correspond to this standard's names. There is no support for
35
+ # aliases or translations yet.
36
+ #
37
+ # @return [OpenStruct]
38
+ #
39
+ # An OpenStruct instance with preset fields: data.name,
40
+ # data.code2, data.code3 and data.number which corresponds to the
41
+ # respective standard's values e.g. Country, A 2, A 3, Number.
42
+ #
43
+ # You can add more fields to this object (as it is an OpenStruct), it will
44
+ # be shared between all calls of for_name and for_code, unless
45
+ # import_iso3166 will be called, what will effectively reset all data
46
+ # objects to default state.
47
+ #
48
+ # nil if there is no such country
49
+ #
50
+ def for_name name
51
+ @countries[UnicodeUtils.upcase name]
52
+ end
53
+
54
+ # Return ISO3166 data for a country code which could be of type 2 or 3, respectfully,
55
+ # 2 or 3 characters long, any case. For data format see Iso3166.for_name
56
+ def for_code code
57
+ code.length == 2 ? @codes2[code.upcase] : @codes3[code.upcase]
58
+ end
59
+
60
+ # Import country definitions file. The file format is as for Iso3166,
61
+ # see below. There is no need to call this method unless you want to override
62
+ # standard definitions in the file below.
63
+ #
64
+ # Note that it will redefine all country data objects so all user-added fields would be
65
+ # lost.
66
+ def import_iso3166 iso3166
67
+ rex = /(.*?)\s+([A-Z]{2})\s+([A-Z]{3})\s+(\d+)/
68
+ @countries = { }
69
+ @codes2 = { }
70
+ @codes3 = { }
71
+ @numbers = { }
72
+
73
+ iso3166.each_line { |s|
74
+ name, code2, code3, number = s.match(rex)[1..-1]
75
+ name.strip!
76
+ data = OpenStruct.new name: name, code2: code2, code3: code3, number: number.to_i
77
+ @countries[UnicodeUtils.upcase name] = data
78
+ @codes2[code2] = data
79
+ @codes3[code3] = data
80
+ @numbers[number] = data
81
+ }
82
+ end
83
+
84
+ # Just like import, same data, create aliases if need for the same codes
85
+ def import_aliases aliases
86
+ aliases.each_line { |a|
87
+ begin
88
+ @@alias_rex ||= /(.*?)\s+([A-Z]{2})($|\s)/u
89
+ name, code2 = a.match(@@alias_rex)[1..-1]
90
+ name.strip!
91
+ add_alias code2, name
92
+ rescue
93
+ puts "Can't process alias line: '#{a.chomp}'"
94
+ raise
95
+ end
96
+ }
97
+ end
98
+
99
+ def add_alias code, name
100
+ if (data = for_code(code)) && data.name != name
101
+ data.name_aliases ||= []
102
+ data.name_aliases << name
103
+ @countries[UnicodeUtils.upcase name] = data
104
+ end
105
+ end
106
+
107
+ def to_objc
108
+ res = ["NSMutableDictionary* countries = @{"]
109
+ @countries.values.each { |c|
110
+ res << " @\"#{c.code2}\" : @{ @\"name\" : @\"#{c.name}\", @\"code2\" : @\"#{c.code2}\", @\"code3\" : @\"#{c.code3}\" },"
111
+ }
112
+ res << "};"
113
+ res.join "\n"
114
+ end
115
+ end
116
+ end
117
+
118
+
119
+ # Return ISO3166 data for a country code which could be of type 2 or 3, respectfully,
120
+ # 2 or 3 characters long, any case. For data format see Iso3166.for_name
121
+ def for_code code
122
+ Coder.for_code code
123
+ end
124
+
125
+ # Return ISO3166 data for a given country name, which is case insensitive
126
+ # but should correspond to this standard's names. There is no support for
127
+ # aliases or translations yet.
128
+ #
129
+ # @return [OpenStruct]
130
+ #
131
+ # An OpenStruct instance with preset fields: data.name,
132
+ # data.code2, data.code3 and data.number which corresponds to the
133
+ # respective standard's values e.g. Country, A 2, A 3, Number.
134
+ #
135
+ # You can add more fields to this object (as it is an OpenStruct), it will
136
+ # be shared between all calls of for_name and for_code, unless
137
+ # import_iso3166 will be called, what will effectively reset all data
138
+ # objects to default state.
139
+ #
140
+ # nil if there is no such country
141
+ #
142
+ def for_name name
143
+ Coder.for_name name
144
+ end
145
+
146
+ def add_alias code, name
147
+ Coder.add_alias code, name
148
+ end
149
+
150
+ module_function :for_code, :for_name, :add_alias
151
+
152
+ end
153
+
154
+ #
155
+ # The countries definition is by intention 'plain', so you can easily update it
156
+ # or provide your own from sources like http://userpage.chemie.fu-berlin.de/diverse/doc/ISO_3166.html
157
+ #
158
+ _iso3166 = <<-End
159
+ AALAND ISLANDS AX ALA 248
160
+ AFGHANISTAN AF AFG 004
161
+ ALBANIA AL ALB 008
162
+ ALGERIA DZ DZA 012
163
+ AMERICAN SAMOA AS ASM 016
164
+ ANDORRA AD AND 020
165
+ ANGOLA AO AGO 024
166
+ ANGUILLA AI AIA 660
167
+ ANTARCTICA AQ ATA 010
168
+ ANTIGUA AND BARBUDA AG ATG 028
169
+ ARGENTINA AR ARG 032
170
+ ARMENIA AM ARM 051
171
+ ARUBA AW ABW 533
172
+ AUSTRALIA AU AUS 036
173
+ AUSTRIA AT AUT 040
174
+ AZERBAIJAN AZ AZE 031
175
+ BAHAMAS BS BHS 044
176
+ BAHRAIN BH BHR 048
177
+ BANGLADESH BD BGD 050
178
+ BARBADOS BB BRB 052
179
+ BELARUS BY BLR 112
180
+ BELGIUM BE BEL 056
181
+ BELIZE BZ BLZ 084
182
+ BENIN BJ BEN 204
183
+ BERMUDA BM BMU 060
184
+ BHUTAN BT BTN 064
185
+ BOLIVIA BO BOL 068
186
+ BOSNIA AND HERZEGOWINA BA BIH 070
187
+ BOTSWANA BW BWA 072
188
+ BOUVET ISLAND BV BVT 074
189
+ BRAZIL BR BRA 076
190
+ BRITISH INDIAN OCEAN TERRITORY IO IOT 086
191
+ BRUNEI DARUSSALAM BN BRN 096
192
+ BULGARIA BG BGR 100
193
+ BURKINA FASO BF BFA 854
194
+ BURUNDI BI BDI 108
195
+ CAMBODIA KH KHM 116
196
+ CAMEROON CM CMR 120
197
+ CANADA CA CAN 124
198
+ CAPE VERDE CV CPV 132
199
+ CAYMAN ISLANDS KY CYM 136
200
+ CENTRAL AFRICAN REPUBLIC CF CAF 140
201
+ CHAD TD TCD 148
202
+ CHILE CL CHL 152
203
+ CHINA CN CHN 156
204
+ CHRISTMAS ISLAND CX CXR 162
205
+ COCOS (KEELING) ISLANDS CC CCK 166
206
+ COLOMBIA CO COL 170
207
+ COMOROS KM COM 174
208
+ CONGO, Democratic Republic of (was Zaire) CD COD 180
209
+ CONGO, Republic of CG COG 178
210
+ COOK ISLANDS CK COK 184
211
+ COSTA RICA CR CRI 188
212
+ COTE D'IVOIRE CI CIV 384
213
+ CROATIA (local name: Hrvatska) HR HRV 191
214
+ CUBA CU CUB 192
215
+ CYPRUS CY CYP 196
216
+ CZECH REPUBLIC CZ CZE 203
217
+ DENMARK DK DNK 208
218
+ DJIBOUTI DJ DJI 262
219
+ DOMINICA DM DMA 212
220
+ DOMINICAN REPUBLIC DO DOM 214
221
+ ECUADOR EC ECU 218
222
+ EGYPT EG EGY 818
223
+ EL SALVADOR SV SLV 222
224
+ EQUATORIAL GUINEA GQ GNQ 226
225
+ ERITREA ER ERI 232
226
+ ESTONIA EE EST 233
227
+ ETHIOPIA ET ETH 231
228
+ FALKLAND ISLANDS (MALVINAS) FK FLK 238
229
+ FAROE ISLANDS FO FRO 234
230
+ FIJI FJ FJI 242
231
+ FINLAND FI FIN 246
232
+ FRANCE FR FRA 250
233
+ FRENCH GUIANA GF GUF 254
234
+ FRENCH POLYNESIA PF PYF 258
235
+ FRENCH SOUTHERN TERRITORIES TF ATF 260
236
+ GABON GA GAB 266
237
+ GAMBIA GM GMB 270
238
+ GEORGIA GE GEO 268
239
+ GERMANY DE DEU 276
240
+ GHANA GH GHA 288
241
+ GIBRALTAR GI GIB 292
242
+ GREECE GR GRC 300
243
+ GREENLAND GL GRL 304
244
+ GRENADA GD GRD 308
245
+ GUADELOUPE GP GLP 312
246
+ GUAM GU GUM 316
247
+ GUATEMALA GT GTM 320
248
+ GUINEA GN GIN 324
249
+ GUINEA-BISSAU GW GNB 624
250
+ GUYANA GY GUY 328
251
+ HAITI HT HTI 332
252
+ HEARD AND MC DONALD ISLANDS HM HMD 334
253
+ HONDURAS HN HND 340
254
+ HONG KONG HK HKG 344
255
+ HUNGARY HU HUN 348
256
+ ICELAND IS ISL 352
257
+ INDIA IN IND 356
258
+ INDONESIA ID IDN 360
259
+ IRAN (ISLAMIC REPUBLIC OF) IR IRN 364
260
+ IRAQ IQ IRQ 368
261
+ IRELAND IE IRL 372
262
+ ISRAEL IL ISR 376
263
+ ITALY IT ITA 380
264
+ JAMAICA JM JAM 388
265
+ JAPAN JP JPN 392
266
+ JORDAN JO JOR 400
267
+ KAZAKHSTAN KZ KAZ 398
268
+ KENYA KE KEN 404
269
+ KIRIBATI KI KIR 296
270
+ KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF KP PRK 408
271
+ KOREA, REPUBLIC OF KR KOR 410
272
+ KUWAIT KW KWT 414
273
+ KYRGYZSTAN KG KGZ 417
274
+ LAO PEOPLE'S DEMOCRATIC REPUBLIC LA LAO 418
275
+ LATVIA LV LVA 428
276
+ LEBANON LB LBN 422
277
+ LESOTHO LS LSO 426
278
+ LIBERIA LR LBR 430
279
+ LIBYAN ARAB JAMAHIRIYA LY LBY 434
280
+ LIECHTENSTEIN LI LIE 438
281
+ LITHUANIA LT LTU 440
282
+ LUXEMBOURG LU LUX 442
283
+ MACAU MO MAC 446
284
+ MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF MK MKD 807
285
+ MADAGASCAR MG MDG 450
286
+ MALAWI MW MWI 454
287
+ MALAYSIA MY MYS 458
288
+ MALDIVES MV MDV 462
289
+ MALI ML MLI 466
290
+ MALTA MT MLT 470
291
+ MARSHALL ISLANDS MH MHL 584
292
+ MARTINIQUE MQ MTQ 474
293
+ MAURITANIA MR MRT 478
294
+ MAURITIUS MU MUS 480
295
+ MAYOTTE YT MYT 175
296
+ MEXICO MX MEX 484
297
+ MICRONESIA, FEDERATED STATES OF FM FSM 583
298
+ MOLDOVA, REPUBLIC OF MD MDA 498
299
+ MONACO MC MCO 492
300
+ MONGOLIA MN MNG 496
301
+ MONTSERRAT MS MSR 500
302
+ MOROCCO MA MAR 504
303
+ MOZAMBIQUE MZ MOZ 508
304
+ MYANMAR MM MMR 104
305
+ NAMIBIA NA NAM 516
306
+ NAURU NR NRU 520
307
+ NEPAL NP NPL 524
308
+ NETHERLANDS NL NLD 528
309
+ NETHERLANDS ANTILLES AN ANT 530
310
+ NEW CALEDONIA NC NCL 540
311
+ NEW ZEALAND NZ NZL 554
312
+ NICARAGUA NI NIC 558
313
+ NIGER NE NER 562
314
+ NIGERIA NG NGA 566
315
+ NIUE NU NIU 570
316
+ NORFOLK ISLAND NF NFK 574
317
+ NORTHERN MARIANA ISLANDS MP MNP 580
318
+ NORWAY NO NOR 578
319
+ OMAN OM OMN 512
320
+ PAKISTAN PK PAK 586
321
+ PALAU PW PLW 585
322
+ PALESTINIAN TERRITORY, Occupied PS PSE 275
323
+ PANAMA PA PAN 591
324
+ PAPUA NEW GUINEA PG PNG 598
325
+ PARAGUAY PY PRY 600
326
+ PERU PE PER 604
327
+ PHILIPPINES PH PHL 608
328
+ PITCAIRN PN PCN 612
329
+ POLAND PL POL 616
330
+ PORTUGAL PT PRT 620
331
+ PUERTO RICO PR PRI 630
332
+ QATAR QA QAT 634
333
+ REUNION RE REU 638
334
+ ROMANIA RO ROU 642
335
+ RUSSIAN FEDERATION RU RUS 643
336
+ RWANDA RW RWA 646
337
+ SAINT HELENA SH SHN 654
338
+ SAINT KITTS AND NEVIS KN KNA 659
339
+ SAINT LUCIA LC LCA 662
340
+ SAINT PIERRE AND MIQUELON PM SPM 666
341
+ SAINT VINCENT AND THE GRENADINES VC VCT 670
342
+ SAMOA WS WSM 882
343
+ SAN MARINO SM SMR 674
344
+ SAO TOME AND PRINCIPE ST STP 678
345
+ SAUDI ARABIA SA SAU 682
346
+ SENEGAL SN SEN 686
347
+ SERBIA AND MONTENEGRO CS SCG 891
348
+ SEYCHELLES SC SYC 690
349
+ SIERRA LEONE SL SLE 694
350
+ SINGAPORE SG SGP 702
351
+ SLOVAKIA SK SVK 703
352
+ SLOVENIA SI SVN 705
353
+ SOLOMON ISLANDS SB SLB 090
354
+ SOMALIA SO SOM 706
355
+ SOUTH AFRICA ZA ZAF 710
356
+ SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS GS SGS 239
357
+ SPAIN ES ESP 724
358
+ SRI LANKA LK LKA 144
359
+ SUDAN SD SDN 736
360
+ SURINAME SR SUR 740
361
+ SVALBARD AND JAN MAYEN ISLANDS SJ SJM 744
362
+ SWAZILAND SZ SWZ 748
363
+ SWEDEN SE SWE 752
364
+ SWITZERLAND CH CHE 756
365
+ SYRIAN ARAB REPUBLIC SY SYR 760
366
+ TAIWAN TW TWN 158
367
+ TAJIKISTAN TJ TJK 762
368
+ TANZANIA, UNITED REPUBLIC OF TZ TZA 834
369
+ THAILAND TH THA 764
370
+ TIMOR-LESTE TL TLS 626
371
+ TOGO TG TGO 768
372
+ TOKELAU TK TKL 772
373
+ TONGA TO TON 776
374
+ TRINIDAD AND TOBAGO TT TTO 780
375
+ TUNISIA TN TUN 788
376
+ TURKEY TR TUR 792
377
+ TURKMENISTAN TM TKM 795
378
+ TURKS AND CAICOS ISLANDS TC TCA 796
379
+ TUVALU TV TUV 798
380
+ UGANDA UG UGA 800
381
+ UKRAINE UA UKR 804
382
+ UNITED ARAB EMIRATES AE ARE 784
383
+ UNITED KINGDOM GB GBR 826
384
+ UNITED STATES US USA 840
385
+ UNITED STATES MINOR OUTLYING ISLANDS UM UMI 581
386
+ URUGUAY UY URY 858
387
+ UZBEKISTAN UZ UZB 860
388
+ VANUATU VU VUT 548
389
+ VATICAN CITY STATE (HOLY SEE) VA VAT 336
390
+ VENEZUELA VE VEN 862
391
+ VIET NAM VN VNM 704
392
+ VIRGIN ISLANDS (BRITISH) VG VGB 092
393
+ VIRGIN ISLANDS (U.S.) VI VIR 850
394
+ WALLIS AND FUTUNA ISLANDS WF WLF 876
395
+ WESTERN SAHARA EH ESH 732
396
+ YEMEN YE YEM 887
397
+ ZAMBIA ZM ZMB 894
398
+ ZIMBABWE ZW ZWE 716
399
+ End
400
+
401
+ _aliases = <<End
402
+ ÅLAND ISLANDS AX ALA 248
403
+ AFGHANISTAN AF AFG 004
404
+ ALBANIA AL ALB 008
405
+ ALGERIA DZ DZA 012
406
+ AMERICAN SAMOA AS ASM 016
407
+ ANDORRA AD AND 020
408
+ ANGOLA AO AGO 024
409
+ ANGUILLA AI AIA 660
410
+ ANTARCTICA AQ ATA 010
411
+ ANTIGUA AND BARBUDA AG ATG 028
412
+ ARGENTINA AR ARG 032
413
+ ARMENIA AM ARM 051
414
+ ARUBA AW ABW 553
415
+ AUSTRALIA AU AUS 036
416
+ AUSTRIA AT AUT 040
417
+ AZERBAIJAN AZ AZE 031
418
+ BAHAMAS BS BHS 044
419
+ BAHRAIN BH BHR 048
420
+ BANGLADESH BD BGD 050
421
+ BARBADOS BB BRB 052
422
+ BELARUS BY BLR 112
423
+ BELGIUM BE BEL 056
424
+ BELIZE BZ BLZ 084
425
+ BENIN BJ BEN 204
426
+ BERMUDA BM BMU 060
427
+ BHUTAN BT BTN 064
428
+ BOLIVIA, PLURINATIONAL STATE OF BO BOL 068
429
+ BONAIRE, SINT EUSTATIUS AND SABA BQ BES 535
430
+ BOSNIA AND HERZEGOWINA BA BIH 070
431
+ BOTSWANA BW BWA 072
432
+ BOUVET ISLAND BV BVT 074
433
+ BRAZIL BR BRA 076
434
+ BRITISH INDIAN OCEAN TERRITORY IO IOT 086
435
+ BRUNEI DARUSSALAM BN BRN 096
436
+ BULGARIA BG BGR 100
437
+ BURKINA FASO BF BFA 854
438
+ BURUNDI BI BDI 108
439
+ CAMBODIA KH KHM 116
440
+ CAMEROON CM CMR 120
441
+ CANADA CA CAN 124
442
+ CAPE VERDE CV CPV 132
443
+ CAYMAN ISLANDS KY CYM 136
444
+ CENTRAL AFRICAN REPUBLIC CF CAF 140
445
+ CHAD TD TCD 148
446
+ CHILE CL CHL 152
447
+ CHINA CN CHN 156
448
+ CHRISTMAS ISLAND CX CXR 162
449
+ COCOS (KEELING) ISLANDS CC CCK 166
450
+ COLOMBIA CO COL 170
451
+ COMOROS KM COM 174
452
+ CONGO CG COG 178
453
+ CONGO, THE DEMOCRATIC REPUBLIC OF THE CD COD 180
454
+ COOK ISLANDS CK COK 184
455
+ COSTA RICA CR CRI 188
456
+ COTE D'IVOIRE CI CIV 384
457
+ CROATIA (local name Hrvatska) HR HRV 191
458
+ CUBA CU CUB 192
459
+ CURAÇAO CW CUW 531
460
+ CYPRUS CY CYP 196
461
+ CZECH REPUBLIC CZ CZE 203
462
+ DENMARK DK DNK 208
463
+ DJIBOUTI DJ DJI 262
464
+ DOMINICA DM DMA 212
465
+ DOMINICAN REPUBLIC DO DOM 214
466
+ ECUADOR EC ECU 218
467
+ EGYPT EG EGY 818
468
+ EL SALVADOR SV SLV 222
469
+ EQUATORIAL GUINEA GQ GNQ 226
470
+ ERITREA ER ERI 232
471
+ ESTONIA EE EST 233
472
+ ETHIOPIA ET ETH 231
473
+ FALKLAND ISLANDS (MALVINAS) FK FLK 238
474
+ FAROE ISLANDS FO FRO 234
475
+ FIJI FJ FJI 242
476
+ FINLAND FI FIN 246
477
+ FRANCE FR FRA 250
478
+ FRENCH GUIANA GF GUF 254
479
+ FRENCH POLYNESIA PF PYF 258
480
+ FRENCH SOUTHERN TERRITORIES TF ATF 260
481
+ GABON GA GAB 266
482
+ GAMBIA GM GMB 270
483
+ GEORGIA GE GEO 268
484
+ GERMANY DE DEU 276
485
+ GHANA GH GHA 288
486
+ GIBRALTAR GI GIB 292
487
+ GREECE GR GRC 300
488
+ GREENLAND GL GRL 304
489
+ GRENADA GD GRD 308
490
+ GUADELOUPE GP GLP 312
491
+ GUAM GU GUM 316
492
+ GUATEMALA GT GTM 320
493
+ GUERNSEY GG GGY 831
494
+ GUINEA GN GIN 324
495
+ GUINEA-BISSAU GW GNB 624
496
+ GUYANA GY GUY 328
497
+ HAITI HT HTI 332
498
+ HEARD AND MC DONALD ISLANDS HM HMD 334
499
+ HOLY SEE (VATICAN CITY STATE) VA VAT 336
500
+ HONDURAS HN HND 340
501
+ HONG KONG HK HKG 344
502
+ HUNGARY HU HUN 348
503
+ ICELAND IS ISL 352
504
+ INDIA IN IND 356
505
+ INDONESIA ID IDN 360
506
+ IRAN (ISLAMIC REPUBLIC OF) IR IRN 364
507
+ IRAQ IQ IRQ 368
508
+ IRELAND IE IRL 372
509
+ ISLE OF MAN IM IMN 833
510
+ ISRAEL IL ISR 376
511
+ ITALY IT ITA 380
512
+ JAMAICA JM JAM 388
513
+ JAPAN JP JPN 392
514
+ JERSEY JE JEY 832
515
+ JORDAN JO JOR 400
516
+ KAZAKHSTAN KZ KAZ 398
517
+ KENYA KE KEN 404
518
+ KIRIBATI KI KIR 296
519
+ KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF KP PRK 408
520
+ KOREA, REPUBLIC OF KR KOR 410
521
+ KUWAIT KW KWT 414
522
+ KYRGYZSTAN KG KGZ 417
523
+ LAO PEOPLE'S DEMOCRATIC REPUBLIC LA LAO 418
524
+ LATVIA LV LVA 428
525
+ LEBANON LB LBN 422
526
+ LESOTHO LS LSO 426
527
+ LIBERIA LR LBR 430
528
+ LIBYA LY LBY 434
529
+ LIECHTENSTEIN LI LIE 438
530
+ LITHUANIA LT LTU 440
531
+ LUXEMBOURG LU LUX 442
532
+ MACAO MO MAC 446
533
+ MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF MK MKD 807
534
+ MADAGASCAR MG MDG 450
535
+ MALAWI MW MWI 454
536
+ MALAYSIA MY MYS 458
537
+ MALDIVES MV MDV 462
538
+ MALI ML MLI 466
539
+ MALTA MT MLT 470
540
+ MARSHALL ISLANDS MH MHL 485
541
+ MARTINIQUE MQ MTQ 474
542
+ MAURITANIA MR MRT 478
543
+ MAURITIUS MU MUS 480
544
+ MAYOTTE YT MYT 175
545
+ MEXICO MX MEX 484
546
+ MICRONESIA, FEDERATED STATES OF FM FSM 583
547
+ MOLDOVA, REPUBLIC OF MD MDA 498
548
+ MONACO MC MCO 492
549
+ MONGOLIA MN MNG 496
550
+ MONTENEGRO ME MNE 499
551
+ MONTSERRAT MS MSR 500
552
+ MOROCCO MA MAR 504
553
+ MOZAMBIQUE MZ MOZ 508
554
+ MYANMAR MM MMR 104
555
+ NAMIBIA NA NAM 516
556
+ NAURU NR NRU 520
557
+ NEPAL NP NPL 524
558
+ NETHERLANDS NL NLD 528
559
+ NEW CALEDONIA NC NCL 540
560
+ NEW ZEALAND NZ NZL 554
561
+ NICARAGUA NI NIC 558
562
+ NIGER NE NER 562
563
+ NIGERIA NG NGA 566
564
+ NIUE NU NIU 570
565
+ NORFOLK ISLAND NF NFK 574
566
+ NORTHERN MARIANA ISLANDS MP MNP 580
567
+ NORWAY NO NOR 578
568
+ OMAN OM OMN 512
569
+ PAKISTAN PK PAK 586
570
+ PALAU PW PLW 585
571
+ PALESTINIAN TERRITORY, OCCUPIED PS PSE 275
572
+ PANAMA PA PAN 591
573
+ PAPUA NEW GUINEA PG PNG 598
574
+ PARAGUAY PY PRY 600
575
+ PERU PE PER 604
576
+ PHILIPPINES PH PHL 608
577
+ PITCAIRN PN PCN 612
578
+ POLAND PL POL 616
579
+ PORTUGAL PT PRT 620
580
+ PUERTO RICO PR PRI 630
581
+ QATAR QA QAT 634
582
+ REUNION RE REU 638
583
+ ROMANIA RO ROU 642
584
+ RUSSIAN FEDERATION RU RUS 643
585
+ RWANDA RW RWA 646
586
+ SAINT HELENA, ASCENSION AND TRISTAN DA CUNHA SH SHN 654
587
+ SAINT BARTHÉLEMY BL BLM 652
588
+ SAINT KITTS AND NEVIS KN KNA 659
589
+ SAINT LUCIA LC LCA 662
590
+ SAINT PIERRE AND MIQUELON PM SPM 666
591
+ SAINT VINCENT AND THE GRENADINES VC VCT 670
592
+ SAMOA WS WSM 882
593
+ SAN MARINO SM SMR 674
594
+ SAO TOME AND PRINCIPE ST STP 678
595
+ SAUDI ARABIA SA SAU 682
596
+ SENEGAL SN SEN 686
597
+ SERBIA RS SRB 688
598
+ SEYCHELLES SC SYC 690
599
+ SIERRA LEONE SL SLE 694
600
+ SINGAPORE SG SGP 702
601
+ SINT MAARTEN (DUTCH PART) SX SXM 534
602
+ SLOVAKIA SK SVK 703
603
+ SLOVENIA SI SVN 705
604
+ SOLOMON ISLANDS SB SLB 090
605
+ SOMALIA SO SOM 706
606
+ SOUTH AFRICA ZA ZAF 710
607
+ SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS GS SGS 239
608
+ SOUTH SUDAN SS SSD 728
609
+ SPAIN ES ESP 724
610
+ SRI LANKA LK LKA 144
611
+ SUDAN SD SDN 729
612
+ SURINAME SR SUR 740
613
+ SVALBARD AND JAN MAYEN ISLANDS SJ SJM 744
614
+ SWAZILAND SZ SWZ 748
615
+ SWEDEN SE SWE 752
616
+ SWITZERLAND CH CHE 756
617
+ SYRIAN ARAB REPUBLIC SY SYR 760
618
+ TAIWAN, PROVINCE OF CHINA TW TWN 158
619
+ TAJIKISTAN TJ TJK 762
620
+ TANZANIA, UNITED REPUBLIC OF TZ TZA 834
621
+ THAILAND TH THA 764
622
+ TIMOR-LESTE TL TLS 626
623
+ TOGO TG TGO 768
624
+ TOKELAU TK TKL 772
625
+ TONGA TO TON 776
626
+ TRINIDAD AND TOBAGO TT TTO 780
627
+ TUNISIA TN TUN 788
628
+ TURKEY TR TUR 792
629
+ TURKMENISTAN TM TKM 795
630
+ TURKS AND CAICOS ISLANDS TC TCA 796
631
+ TUVALU TV TUV 798
632
+ UGANDA UG UGA 800
633
+ UKRAINE UA UKR 804
634
+ UNITED ARAB EMIRATES AE ARE 784
635
+ UNITED KINGDOM* GB GBR 826
636
+ UNITED STATES US USA 840
637
+ UNITED STATES MINOR OUTLYING ISLANDS UM UMI 581
638
+ URUGUAY UY URY 858
639
+ UZBEKISTAN UZ UZB 860
640
+ VANUATU VU VUT 548
641
+ VENEZUELA, BOLIVARIAN REPUBLIC OF VE VEN 862
642
+ VIET NAM VN VNM 704
643
+ VIRGIN ISLANDS (BRITISH) VG VGB 092
644
+ VIRGIN ISLANDS (U.S.) VI VIR 850
645
+ WALLIS AND FUTUNA ISLANDS WF WLF 876
646
+ WESTERN SAHARA EH ESH 732
647
+ YEMEN YE YEM 887
648
+ ZAMBIA ZM ZMB 894
649
+ ZIMBABWE ZW ZWE 716
650
+ End
651
+
652
+ _more_aliases = <<End
653
+ USA US
654
+ США US
655
+ Россия RU
656
+ РФ RU
657
+ Russia RU
658
+ Great Britain GB
659
+ England GB
660
+ End
661
+
662
+
663
+ # By default, initialize with contents above
664
+ Iso3166::Coder.import_iso3166 _iso3166
665
+ Iso3166::Coder.import_aliases _aliases
666
+ Iso3166::Coder.import_aliases _more_aliases
667
+
668
+
669
+
@@ -0,0 +1,3 @@
1
+ module Iso3166
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+ require 'iso_3166'
3
+
4
+ describe Iso3166 do
5
+ it 'should return valid data' do
6
+ data = Iso3166.for_name('UNIted STATES MINOR OUTLYING ISLANDs')
7
+ data.should_not be_nil
8
+ data.name.should == 'UNITED STATES MINOR OUTLYING ISLANDS'
9
+ data.code2.should == 'UM'
10
+ data.code3.should == 'UMI'
11
+ data.number.should == 581
12
+
13
+ #SWEDEN SE SWE 752
14
+ data = Iso3166.for_code 'SE'
15
+ data.name.should == 'SWEDEN'
16
+ data.code2.should == 'SE'
17
+ data.code3.should == 'SWE'
18
+ data.number.should == 752
19
+
20
+ data = Iso3166.for_code 'SWE'
21
+ data.name.should == 'SWEDEN'
22
+ data.code2.should == 'SE'
23
+ data.code3.should == 'SWE'
24
+ data.number.should == 752
25
+ end
26
+
27
+ it 'should detect aliases' do
28
+ Iso3166.for_name('USA').code2.should == 'US'
29
+ Iso3166.for_name('США').code2.should == 'US'
30
+ Iso3166.for_name('Россия').code3.should == 'RUS'
31
+ Iso3166.for_name('РОСсия').code3.should == 'RUS'
32
+ Iso3166.for_name('russia').code3.should == 'RUS'
33
+ Iso3166.for_name('england').code2.should == 'GB'
34
+ end
35
+
36
+ it 'should add aliases' do
37
+ Iso3166.add_alias 'AU', 'Oz'
38
+ Iso3166.for_name('OZ').code2.should == 'AU'
39
+ end
40
+ end
@@ -0,0 +1,17 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iso_3166
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - sergeych
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Utility class to deal with ISO3166 country codes, names and number
31
+ email:
32
+ - real.sergeych@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - .rspec
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - iso_countries.gemspec
44
+ - lib/iso_3166.rb
45
+ - lib/iso_3166/version.rb
46
+ - spec/coder_spec.rb
47
+ - spec/spec_helper.rb
48
+ homepage: ''
49
+ licenses: []
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 1.8.24
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: ''
72
+ test_files:
73
+ - spec/coder_spec.rb
74
+ - spec/spec_helper.rb