itu_codes 0.2 → 0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README +54 -0
- data/lib/itu_codes/version.rb +3 -0
- data/lib/itu_codes.rb +500 -444
- metadata +72 -30
- data/History.txt +0 -7
- data/Manifest.txt +0 -6
- data/README.txt +0 -12
- data/Rakefile +0 -9
- data/test/itu_codes_test.rb +0 -61
data/lib/itu_codes.rb
CHANGED
@@ -2,472 +2,528 @@
|
|
2
2
|
# 1 --> Non-US need to be separated by area code
|
3
3
|
# 7 --> Kazakhstan!
|
4
4
|
require 'enumerator'
|
5
|
+
require 'carmen'
|
5
6
|
|
6
|
-
|
7
|
-
VERSION = '0.2'
|
7
|
+
# TODO: add ability to search for common names (i.e. 'USA' or 'United States of America' for 'United States')
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
9
|
+
module ItuCodes
|
10
|
+
include Carmen
|
11
|
+
|
12
|
+
# TODO: move the base data into a fixture file to speed up loading
|
13
|
+
CODE_LIST = [
|
14
|
+
{ "0" => "Reserved"},
|
15
|
+
|
16
|
+
{ "1" => "United States"},
|
17
|
+
|
18
|
+
# from http://www.cnac.ca/co_codes/co_code_status_map.htm
|
19
|
+
{ "1" => "Canada" },
|
20
|
+
{ "1250" => "Canada" },
|
21
|
+
{ "1204" => "Canada" },
|
22
|
+
{ "1226" => "Canada" },
|
23
|
+
{ "1250" => "Canada" },
|
24
|
+
{ "1289" => "Canada" },
|
25
|
+
{ "1306" => "Canada" },
|
26
|
+
{ "1343" => "Canada" },
|
27
|
+
{ "1403" => "Canada" },
|
28
|
+
{ "1416" => "Canada" },
|
29
|
+
{ "1418" => "Canada" },
|
30
|
+
{ "1438" => "Canada" },
|
31
|
+
{ "1450" => "Canada" },
|
32
|
+
{ "1506" => "Canada" },
|
33
|
+
{ "1514" => "Canada" },
|
34
|
+
{ "1519" => "Canada" },
|
35
|
+
{ "1581" => "Canada" },
|
36
|
+
{ "1587" => "Canada" },
|
37
|
+
{ "1604" => "Canada" },
|
38
|
+
{ "1613" => "Canada" },
|
39
|
+
{ "1647" => "Canada" },
|
40
|
+
{ "1705" => "Canada" },
|
41
|
+
{ "1709" => "Canada" },
|
42
|
+
{ "1778" => "Canada" },
|
43
|
+
{ "1780" => "Canada" },
|
44
|
+
{ "1807" => "Canada" },
|
45
|
+
{ "1819" => "Canada" },
|
46
|
+
{ "1867" => "Canada" },
|
47
|
+
{ "1902" => "Canada" },
|
48
|
+
{ "1905" => "Canada" },
|
49
|
+
|
50
|
+
{ "1" => "American Samoa" },
|
51
|
+
{ "1684" => "American Samoa" },
|
52
|
+
|
53
|
+
{ "1" => "Anguilla" },
|
54
|
+
{ "1264" => "Anguilla" },
|
55
|
+
|
56
|
+
{ "1" => "Antigua and Barbuda" },
|
57
|
+
{ "1268" => "Antigua and Barbuda" },
|
58
|
+
|
59
|
+
{ "1" => "Bahamas" },
|
60
|
+
{ "1242" => "Bahamas" },
|
61
|
+
|
62
|
+
{ "1" => "Barbados" },
|
63
|
+
{ "1246" => "Barbados" },
|
64
|
+
|
65
|
+
{ "1" => "Bermuda" },
|
66
|
+
{ "1441" => "Bermuda" },
|
67
|
+
|
68
|
+
{ "1" => "British Virgin Islands" },
|
69
|
+
{ "1284" => "British Virgin Islands" },
|
70
|
+
|
71
|
+
{ "1" => "Cayman Islands" },
|
72
|
+
{ "1345" => "Cayman Islands" },
|
73
|
+
|
74
|
+
{ "1" => "Dominica" },
|
75
|
+
{ "1767" => "Dominica" },
|
76
|
+
|
77
|
+
{ "1" => "Dominican Republic" },
|
78
|
+
{ "1809" => "Dominican Republic" },
|
79
|
+
{ "1829" => "Dominican Republic" },
|
80
|
+
|
81
|
+
{ "1" => "Grenada" },
|
82
|
+
{ "1473" => "Grenada" },
|
83
|
+
|
84
|
+
{ "1" => "Guam" },
|
85
|
+
{ "1671" => "Guam" },
|
86
|
+
|
87
|
+
{ "1" => "Jamaica" },
|
88
|
+
{ "1876" => "Jamaica" },
|
89
|
+
|
90
|
+
{ "1" => "Montserrat" },
|
91
|
+
{ "1664" => "Montserrat" },
|
92
|
+
|
93
|
+
{ "1" => "Northern Mariana Islands" },
|
94
|
+
{ "1670" => "Northern Mariana Islands" },
|
95
|
+
|
96
|
+
{ "1" => "Saint Kitts and Nevis" },
|
97
|
+
{ "1869" => "Saint Kitts and Nevis" },
|
98
|
+
|
99
|
+
{ "1" => "Saint Lucia" },
|
100
|
+
{ "1758" => "Saint Lucia" },
|
101
|
+
|
102
|
+
{ "1" => "Saint Vincent and the Grenadines" },
|
103
|
+
{ "1784" => "Saint Vincent and the Grenadines" },
|
104
|
+
|
105
|
+
{ "1" => "Trinidad and Tobago" },
|
106
|
+
{ "1868" => "Trinidad and Tobago" },
|
107
|
+
|
108
|
+
{ "1" => "Turks and Caicos Islands" },
|
109
|
+
{ "1649" => "Turks and Caicos Islands" },
|
110
|
+
|
111
|
+
{ "1" => "United States Virgin Islands" },
|
112
|
+
{ "1340" => "United States Virgin Islands" },
|
113
|
+
|
114
|
+
{"20" => "Egypt"},
|
115
|
+
{"210" => "Spare code"},
|
116
|
+
{"211" => "Spare code"},
|
117
|
+
{"212" => "Morocco"},
|
118
|
+
{"213" => "Algeria"},
|
119
|
+
{"214" => "Spare code"},
|
120
|
+
{"215" => "Spare code"},
|
121
|
+
{"216" => "Tunisia"},
|
122
|
+
{"217" => "Spare code"},
|
123
|
+
{"218" => "Libyan Arab Jamahiriya"},
|
124
|
+
{"219" => "Spare code"},
|
125
|
+
{"220" => "Gambia"},
|
126
|
+
{"221" => "Senegal"},
|
127
|
+
{"222" => "Mauritania"},
|
128
|
+
{"223" => "Mali"},
|
129
|
+
{"224" => "Guinea"},
|
130
|
+
{"225" => "Cote D'ivoire"},
|
131
|
+
{"226" => "Burkina Faso"},
|
132
|
+
{"227" => "Niger"},
|
133
|
+
{"228" => "Togo"},
|
134
|
+
{"229" => "Benin"},
|
135
|
+
{"230" => "Mauritius"},
|
136
|
+
{"231" => "Liberia"},
|
137
|
+
{"232" => "Sierra Leone"},
|
138
|
+
{"233" => "Ghana"},
|
139
|
+
{"234" => "Nigeria"},
|
140
|
+
{"235" => "Chad"},
|
141
|
+
{"236" => "Central African Republic"},
|
142
|
+
{"237" => "Cameroon"},
|
143
|
+
{"238" => "Cape Verde"},
|
144
|
+
{"239" => "Sao Tome and Principe"},
|
145
|
+
{"240" => "Equatorial Guinea"},
|
146
|
+
{"241" => "Gabon"},
|
147
|
+
{"242" => "Congo"},
|
148
|
+
{"243" => "Congo, the Democratic Republic of the"},
|
149
|
+
{"244" => "Angola"},
|
150
|
+
{"245" => "Guinea-Bissau"},
|
151
|
+
{"246" => "Diego Garcia"},
|
152
|
+
{"247" => "Ascension"},
|
153
|
+
{"248" => "Seychelles"},
|
154
|
+
{"249" => "Sudan"},
|
155
|
+
{"250" => "Rwanda"},
|
156
|
+
{"251" => "Ethiopia"},
|
157
|
+
{"252" => "Somalia"},
|
158
|
+
{"253" => "Djibouti"},
|
159
|
+
{"254" => "Kenya"},
|
160
|
+
{"255" => "Tanzania, United Republic of"},
|
161
|
+
{"256" => "Uganda"},
|
162
|
+
{"257" => "Burundi"},
|
163
|
+
{"258" => "Mozambique"},
|
164
|
+
{"259" => "Spare code"},
|
165
|
+
{"260" => "Zambia"},
|
166
|
+
{"261" => "Madagascar"},
|
167
|
+
{"262" => "Reunion"},
|
168
|
+
{"263" => "Zimbabwe"},
|
169
|
+
{"264" => "Namibia"},
|
170
|
+
{"265" => "Malawi"},
|
171
|
+
{"266" => "Lesotho"},
|
172
|
+
{"267" => "Botswana"},
|
173
|
+
{"268" => "Swaziland"},
|
174
|
+
{"269" => "Comoros"},
|
175
|
+
{"269" => "Mayotte"},
|
176
|
+
{"27" => "South Africa"},
|
177
|
+
{"280" => "Spare code"},
|
178
|
+
{"281" => "Spare code"},
|
179
|
+
{"282" => "Spare code"},
|
180
|
+
{"283" => "Spare code"},
|
181
|
+
{"284" => "Spare code"},
|
182
|
+
{"285" => "Spare code"},
|
183
|
+
{"286" => "Spare code"},
|
184
|
+
{"287" => "Spare code"},
|
185
|
+
{"288" => "Spare code"},
|
186
|
+
{"289" => "Spare code"},
|
187
|
+
{"290" => "Saint Helena"},
|
188
|
+
{"291" => "Eritrea"},
|
189
|
+
{"292" => "Spare code"},
|
190
|
+
{"293" => "Spare code"},
|
191
|
+
{"294" => "Spare code"},
|
192
|
+
{"295" => "Spare code"},
|
193
|
+
{"296" => "Spare code"},
|
194
|
+
{"297" => "Aruba"},
|
195
|
+
{"298" => "Faroe Islands"},
|
196
|
+
{"299" => "Greenland"},
|
197
|
+
{"30" => "Greece"},
|
198
|
+
{"31" => "Netherlands"},
|
199
|
+
{"32" => "Belgium"},
|
200
|
+
{"33" => "France"},
|
201
|
+
{"34" => "Spain"},
|
202
|
+
{"350" => "Gibraltar"},
|
203
|
+
{"351" => "Portugal"},
|
204
|
+
{"352" => "Luxembourg"},
|
205
|
+
{"353" => "Ireland"},
|
206
|
+
{"354" => "Iceland"},
|
207
|
+
{"355" => "Albania"},
|
208
|
+
{"356" => "Malta"},
|
209
|
+
{"357" => "Cyprus"},
|
210
|
+
{"358" => "Finland"},
|
211
|
+
{"359" => "Bulgaria"},
|
212
|
+
{"36" => "Hungary"},
|
213
|
+
{"370" => "Lithuania"},
|
214
|
+
{"371" => "Latvia"},
|
215
|
+
{"372" => "Estonia"},
|
216
|
+
{"373" => "Moldova, Republic of"},
|
217
|
+
{"374" => "Armenia"},
|
218
|
+
{"375" => "Belarus"},
|
219
|
+
{"376" => "Andorra"},
|
220
|
+
{"377" => "Monaco"},
|
221
|
+
{"378" => "San Marino"},
|
222
|
+
{"379" => "Holy See (Vatican City State},"},
|
223
|
+
{"380" => "Ukraine"},
|
224
|
+
{"381" => "Serbia and Montenegro"},
|
225
|
+
{"382" => "Spare code"},
|
226
|
+
{"383" => "Spare code"},
|
227
|
+
{"384" => "Spare code"},
|
228
|
+
{"385" => "Croatia"},
|
229
|
+
{"386" => "Slovenia"},
|
230
|
+
{"387" => "Bosnia and Herzegovina"},
|
231
|
+
{"388" => "Group of countries, shared code"},
|
232
|
+
{"389" => "Macedonia, the Former Yugoslav Republic of"},
|
233
|
+
{"39" => "Italy"},
|
234
|
+
{"40" => "Romania"},
|
235
|
+
{"41" => "Switzerland"},
|
236
|
+
{"420" => "Czech Republic"},
|
237
|
+
{"421" => "Slovakia"},
|
238
|
+
{"422" => "Spare code"},
|
239
|
+
{"423" => "Liechtenstein"},
|
240
|
+
{"424" => "Spare code"},
|
241
|
+
{"425" => "Spare code"},
|
242
|
+
{"426" => "Spare code"},
|
243
|
+
{"427" => "Spare code"},
|
244
|
+
{"428" => "Spare code"},
|
245
|
+
{"429" => "Spare code"},
|
246
|
+
{"43" => "Austria"},
|
247
|
+
{"44" => "United Kingdom"},
|
248
|
+
{"45" => "Denmark"},
|
249
|
+
{"46" => "Sweden"},
|
250
|
+
{"47" => "Norway"},
|
251
|
+
{"48" => "Poland"},
|
252
|
+
{"49" => "Germany"},
|
253
|
+
{"500" => "Falkland Islands"},
|
254
|
+
{"501" => "Belize"},
|
255
|
+
{"502" => "Guatemala"},
|
256
|
+
{"503" => "El Salvador"},
|
257
|
+
{"504" => "Honduras"},
|
258
|
+
{"505" => "Nicaragua"},
|
259
|
+
{"506" => "Costa Rica"},
|
260
|
+
{"507" => "Panama"},
|
261
|
+
{"508" => "Saint Pierre and Miquelon"},
|
262
|
+
{"509" => "Haiti"},
|
263
|
+
{"51" => "Peru"},
|
264
|
+
{"52" => "Mexico"},
|
265
|
+
{"53" => "Cuba"},
|
266
|
+
{"54" => "Argentina"},
|
267
|
+
{"55" => "Brazil"},
|
268
|
+
{"56" => "Chile"},
|
269
|
+
{"57" => "Colombia"},
|
270
|
+
{"58" => "Venezuela"},
|
271
|
+
{"590" => "Guadeloupe"},
|
272
|
+
{"591" => "Bolivia"},
|
273
|
+
{"592" => "Guyana"},
|
274
|
+
{"593" => "Ecuador"},
|
275
|
+
{"594" => "French Guiana"},
|
276
|
+
{"595" => "Paraguay"},
|
277
|
+
{"596" => "Martinique"},
|
278
|
+
{"597" => "Suriname"},
|
279
|
+
{"598" => "Uruguay"},
|
280
|
+
{"599" => "Netherlands Antilles"},
|
281
|
+
{"60" => "Malaysia"},
|
282
|
+
{"61" => "Australia"},
|
283
|
+
{"62" => "Indonesia"},
|
284
|
+
{"63" => "Philippines"},
|
285
|
+
{"64" => "New Zealand"},
|
286
|
+
{"65" => "Singapore"},
|
287
|
+
{"66" => "Thailand"},
|
288
|
+
{"670" => "Timor-Leste"},
|
289
|
+
{"671" => "Spare code"},
|
290
|
+
{"672" => "Australian External Territories"},
|
291
|
+
{"673" => "Brunei Darussalam"},
|
292
|
+
{"674" => "Nauru"},
|
293
|
+
{"675" => "Papua New Guinea"},
|
294
|
+
{"676" => "Tonga"},
|
295
|
+
{"677" => "Solomon Islands"},
|
296
|
+
{"678" => "Vanuatu"},
|
297
|
+
{"679" => "Fiji"},
|
298
|
+
{"680" => "Palau"},
|
299
|
+
{"681" => "Wallis and Futuna"},
|
300
|
+
{"682" => "Cook Islands"},
|
301
|
+
{"683" => "Niue"},
|
302
|
+
{"684" => "Spare code"},
|
303
|
+
{"685" => "Samoa"},
|
304
|
+
{"686" => "Kiribati"},
|
305
|
+
{"687" => "New Caledonia"},
|
306
|
+
{"688" => "Tuvalu"},
|
307
|
+
{"689" => "French Polynesia"},
|
308
|
+
{"690" => "Tokelau"},
|
309
|
+
{"691" => "Micronesia, Federated States of"},
|
310
|
+
{"692" => "Marshall Islands"},
|
311
|
+
{"693" => "Spare code"},
|
312
|
+
{"694" => "Spare code"},
|
313
|
+
{"695" => "Spare code"},
|
314
|
+
{"696" => "Spare code"},
|
315
|
+
{"697" => "Spare code"},
|
316
|
+
{"698" => "Spare code"},
|
317
|
+
{"699" => "Spare code"},
|
318
|
+
|
319
|
+
{"7" => "Russian Federation"},
|
320
|
+
{"7" => "Kazakhstan"},
|
321
|
+
|
322
|
+
{"800" => "International Freephone Service"},
|
323
|
+
{"801" => "Spare code"},
|
324
|
+
{"802" => "Spare code"},
|
325
|
+
{"803" => "Spare code"},
|
326
|
+
{"804" => "Spare code"},
|
327
|
+
{"805" => "Spare code"},
|
328
|
+
{"806" => "Spare code"},
|
329
|
+
{"807" => "Spare code"},
|
330
|
+
{"808" => "International Shared Cost Service"},
|
331
|
+
{"809" => "Spare code"},
|
332
|
+
{"81" => "Japan"},
|
333
|
+
{"82" => "Korea, Republic of"},
|
334
|
+
{"830" => "Spare code"},
|
335
|
+
{"831" => "Spare code"},
|
336
|
+
{"832" => "Spare code"},
|
337
|
+
{"833" => "Spare code"},
|
338
|
+
{"834" => "Spare code"},
|
339
|
+
{"835" => "Spare code"},
|
340
|
+
{"836" => "Spare code"},
|
341
|
+
{"837" => "Spare code"},
|
342
|
+
{"838" => "Spare code"},
|
343
|
+
{"839" => "Spare code"},
|
344
|
+
{"84" => "Viet Nam"},
|
345
|
+
{"850" => "Korea, Democratic People's Republic of"},
|
346
|
+
{"851" => "Spare code"},
|
347
|
+
{"852" => "Hong Kong"},
|
348
|
+
{"853" => "Macao"},
|
349
|
+
{"854" => "Spare code"},
|
350
|
+
{"855" => "Cambodia"},
|
351
|
+
{"856" => "Lao People's Democratic Republic"},
|
352
|
+
{"857" => "Spare code"},
|
353
|
+
{"858" => "Spare code"},
|
354
|
+
{"859" => "Spare code"},
|
355
|
+
{"86" => "China"},
|
356
|
+
{"870" => "Inmarsat SNAC"},
|
357
|
+
{"871" => "Inmarsat"},
|
358
|
+
{"872" => "Inmarsat"},
|
359
|
+
{"873" => "Inmarsat"},
|
360
|
+
{"874" => "Inmarsat"},
|
361
|
+
{"875" => "Reserved - Maritime Mobile Service Applications"},
|
362
|
+
{"876" => "Reserved - Maritime Mobile Service Applications"},
|
363
|
+
{"877" => "Reserved - Maritime Mobile Service Applications"},
|
364
|
+
{"878" => "Universal Personal Telecommunication Service"},
|
365
|
+
{"879" => "Reserved for national non-commercial purposes"},
|
366
|
+
{"880" => "Bangladesh"},
|
367
|
+
{"881" => "International Mobile, shared code"},
|
368
|
+
{"882" => "International Networks, shared code"},
|
369
|
+
{"883" => "Spare code"},
|
370
|
+
{"884" => "Spare code"},
|
371
|
+
{"885" => "Spare code"},
|
372
|
+
{"886" => "Reserved"},
|
373
|
+
{"887" => "Spare code"},
|
374
|
+
{"888" => "Reserved for future global service"},
|
375
|
+
{"889" => "Spare code"},
|
376
|
+
{"890" => "Spare code"},
|
377
|
+
{"891" => "Spare code"},
|
378
|
+
{"892" => "Spare code"},
|
379
|
+
{"893" => "Spare code"},
|
380
|
+
{"894" => "Spare code"},
|
381
|
+
{"895" => "Spare code"},
|
382
|
+
{"896" => "Spare code"},
|
383
|
+
{"897" => "Spare code"},
|
384
|
+
{"898" => "Spare code"},
|
385
|
+
{"899" => "Spare code"},
|
386
|
+
{"90" => "Turkey"},
|
387
|
+
{"91" => "India"},
|
388
|
+
{"92" => "Pakistan"},
|
389
|
+
{"93" => "Afghanistan"},
|
390
|
+
{"94" => "Sri Lanka"},
|
391
|
+
{"95" => "Myanmar"},
|
392
|
+
{"960" => "Maldives"},
|
393
|
+
{"961" => "Lebanon"},
|
394
|
+
{"962" => "Jordan"},
|
395
|
+
{"963" => "Syrian Arab Republic"},
|
396
|
+
{"964" => "Iraq"},
|
397
|
+
{"965" => "Kuwait"},
|
398
|
+
{"966" => "Saudi Arabia"},
|
399
|
+
{"967" => "Yemen"},
|
400
|
+
{"968" => "Oman"},
|
401
|
+
{"969" => "Reserved - reservation currently under investigation"},
|
402
|
+
{"970" => "Reserved"},
|
403
|
+
{"971" => "United Arab Emirates"},
|
404
|
+
{"972" => "Israel"},
|
405
|
+
{"973" => "Bahrain"},
|
406
|
+
{"974" => "Qatar"},
|
407
|
+
{"975" => "Bhutan"},
|
408
|
+
{"976" => "Mongolia"},
|
409
|
+
{"977" => "Nepal"},
|
410
|
+
{"978" => "Spare code"},
|
411
|
+
{"979" => "International Premium Rate Service"},
|
412
|
+
{"98" => "Iran, Islamic Republic of"},
|
413
|
+
{"990" => "Spare code"},
|
414
|
+
{"991" => "Trial of a proposed new international telecommunication public correspondence"},
|
415
|
+
{"992" => "Tajikistan"},
|
416
|
+
{"993" => "Turkmenistan"},
|
417
|
+
{"994" => "Azerbaijan"},
|
418
|
+
{"995" => "Georgia"}
|
419
|
+
]
|
371
420
|
|
372
421
|
def self.list
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
# => {"92" => "Pakistan (Islamic Republic of)"},
|
386
|
-
# => {"93" => "Afghanistan"}
|
387
|
-
# => ]
|
388
|
-
def self.find (code_or_name)
|
389
|
-
if code_or_name.to_s.match /[^0-9]/ # non-numeric string passed
|
422
|
+
ItuCodes::CODE_LIST
|
423
|
+
end
|
424
|
+
|
425
|
+
def self.lookup(code)
|
426
|
+
cleaned = clean(code)
|
427
|
+
list.find_all{ |hsh| hsh.keys.first == cleaned }.map do |k|
|
428
|
+
k.values.first
|
429
|
+
end.uniq
|
430
|
+
end
|
431
|
+
|
432
|
+
def self.find (code_or_name)
|
433
|
+
if code_or_name.to_s.match /[^0-9]/ # non-numeric string passed
|
390
434
|
find_by_name(code_or_name)
|
391
435
|
else
|
392
|
-
|
436
|
+
cleaned = self.clean(code_or_name)
|
437
|
+
find_by_itu_code(cleaned)
|
393
438
|
end
|
394
439
|
end
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
440
|
+
|
441
|
+
def self.find_by_itu_code(code)
|
442
|
+
if american?(code) and code.length > 1
|
443
|
+
returner = 'United States'
|
444
|
+
else
|
445
|
+
returner = ItuCodes::CODE_LIST.find_all do |record|
|
446
|
+
record.has_key? code
|
447
|
+
end.map { |k| k.values.first }.uniq
|
399
448
|
end
|
449
|
+
returner.size <= 1 ? returner.shift : returner
|
400
450
|
end
|
401
451
|
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
end
|
452
|
+
def self.find_by_name(name)
|
453
|
+
returner = list.find_all do |record|
|
454
|
+
record.has_value? name
|
455
|
+
end.map{ |k| k.keys.first }.uniq
|
456
|
+
returner.size <= 1 ? returner.shift : returner
|
457
|
+
end
|
458
|
+
|
459
|
+
# ie. find_by_country_iso_code('US')
|
460
|
+
def self.iso2itu(iso_code)
|
461
|
+
ItuCodes.find_by_name( Carmen::country_name(iso_code) ).reject do |c|
|
462
|
+
north_american?(c) and c.length > 1
|
463
|
+
end.shift rescue nil
|
464
|
+
end
|
465
|
+
|
466
|
+
# this is tricky for North American destinations: '1' can be the US, Canada or another country
|
467
|
+
def self.itu2iso(itu_code)
|
468
|
+
ItuCodes.lookup(itu_code).map do |country|
|
469
|
+
Carmen::country_code( country ) rescue nil
|
470
|
+
end.compact
|
406
471
|
end
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
472
|
+
|
473
|
+
# returns true for any valid ITU code
|
474
|
+
# valid_code?(1) => true
|
475
|
+
# valid_code?(1818) => false
|
476
|
+
def self.valid_code?(some_code)
|
477
|
+
if north_american?(some_code)
|
478
|
+
some_code.length == 1
|
412
479
|
else
|
413
|
-
|
480
|
+
self.list.any? { |hsh| hsh.has_key?(some_code) }
|
414
481
|
end
|
415
482
|
end
|
416
483
|
|
484
|
+
def self.north_america
|
485
|
+
find_by_itu_code '1'
|
486
|
+
end
|
487
|
+
|
488
|
+
def self.north_american?(some_code)
|
489
|
+
some_code.to_s[0,1] == '1'
|
490
|
+
end
|
491
|
+
|
417
492
|
# parse a destination code (probably with area code) to find the ITU code
|
418
|
-
# ex: parse_code(1818) =>
|
493
|
+
# ex: parse_code(1818) => 1
|
419
494
|
def self.parse_code(some_code)
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
# http://en.wikipedia.org/wiki/List_of_country_calling_codes
|
424
|
-
if some_code[0,1] == "1" and some_code.length >= 4
|
425
|
-
if valid_code? some_code[0,4] # NOT the US or Canada --> 4 digit country code
|
426
|
-
sub_index = 4
|
427
|
-
else # US or CANADA --> 1 digit country code
|
428
|
-
sub_index = 1
|
429
|
-
end
|
430
|
-
else
|
431
|
-
sub_index = (1..some_code.length).find do |len|
|
432
|
-
valid_code? some_code[0,len]
|
433
|
-
end
|
434
|
-
end
|
435
|
-
some_code[0,sub_index] unless sub_index.nil?
|
436
|
-
end
|
437
|
-
|
438
|
-
def self.parse_area_code(some_code)
|
439
|
-
some_code = some_code.to_s unless some_code.respond_to? :length
|
440
|
-
if parse_code(some_code) and ! valid_code? some_code
|
441
|
-
len = parse_code(some_code).length
|
442
|
-
some_code[len..-1]
|
443
|
-
else
|
444
|
-
nil
|
495
|
+
some_code = clean(some_code)
|
496
|
+
sub_index = (1..some_code.length).find do |len|
|
497
|
+
valid_code? some_code[0,len]
|
445
498
|
end
|
499
|
+
some_code[0,sub_index] unless sub_index.nil?
|
446
500
|
end
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
if valid_code? some_country_code and valid_code? other_country_code
|
455
|
-
returner = some_country_code == other_country_code
|
456
|
-
else
|
457
|
-
returner = nil
|
501
|
+
|
502
|
+
# parse a destination code (probably with area code) to find the number without the ITU code
|
503
|
+
# ex: parse_number(18184443322) => 8184443322
|
504
|
+
def self.parse_number(some_code)
|
505
|
+
some_code = clean(some_code)
|
506
|
+
sub_index = (1..some_code.length).find do |len|
|
507
|
+
valid_code? some_code[0,len]
|
458
508
|
end
|
459
|
-
|
460
|
-
|
509
|
+
some_code[sub_index,some_code.length - sub_index] unless sub_index.nil?
|
510
|
+
end
|
511
|
+
|
512
|
+
def self.compatriots?(some, other)
|
513
|
+
both_valid = ! ( parse_code(some).nil? or parse_code(other).nil? )
|
514
|
+
both_valid and ( parse_code(some) == parse_code(other) ) rescue nil
|
461
515
|
end
|
462
516
|
|
463
517
|
def self.american?(some_code)
|
464
|
-
parse_code
|
518
|
+
# for non-US North American codes, parse_code will return a 4 digit code
|
519
|
+
# for US, '1' will be returned
|
520
|
+
some_code = some_code.to_s
|
521
|
+
countries = lookup(some_code[0,4])
|
522
|
+
north_american?(some_code) and (countries.include?('United States') or countries.empty?)
|
523
|
+
end
|
524
|
+
|
525
|
+
# converts input to string, then strips any non-numeric characters
|
526
|
+
def self.clean(input)
|
527
|
+
input.to_s.gsub(/[^0-9]/, '')
|
465
528
|
end
|
466
|
-
|
467
|
-
end
|
468
|
-
# sample usage:
|
469
|
-
# i = ItuCodes.new
|
470
|
-
# i.valid_code? 8392813 # => false
|
471
|
-
# i.valid_code? 7 # => true
|
472
|
-
# i.parse_code 1818 # => 1
|
473
|
-
# i.parse_code 4 # => nil
|
529
|
+
end
|