itu_codes 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -0
- data/Manifest.txt +6 -0
- data/README.txt +12 -0
- data/Rakefile +9 -0
- data/lib/itu_codes.rb +473 -0
- data/test/itu_codes_test.rb +61 -0
- metadata +71 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
data/Rakefile
ADDED
data/lib/itu_codes.rb
ADDED
@@ -0,0 +1,473 @@
|
|
1
|
+
# to-do: deal with headache codes:
|
2
|
+
# 1 --> Non-US need to be separated by area code
|
3
|
+
# 7 --> Kazakhstan!
|
4
|
+
require 'enumerator'
|
5
|
+
|
6
|
+
class ItuCodes < Object
|
7
|
+
VERSION = '0.2'
|
8
|
+
|
9
|
+
@@CODE_LIST = {
|
10
|
+
"0" => "Reserved",
|
11
|
+
"1" => {
|
12
|
+
"1" => "United States of America",
|
13
|
+
"1684" => "American Samoa",
|
14
|
+
"1264" => "Anguilla",
|
15
|
+
"1268" => "Antigua and Barbuda",
|
16
|
+
"1242" => "Bahamas (Commonwealth of the)",
|
17
|
+
"1246" => "Barbados",
|
18
|
+
"1441" => "Bermuda",
|
19
|
+
"1284" => "British Virgin Islands",
|
20
|
+
"1204" => "Canada", # from http://www.cnac.ca/co_codes/co_code_status_map.htm
|
21
|
+
"1226" => "Canada",
|
22
|
+
"1250" => "Canada",
|
23
|
+
"1289" => "Canada",
|
24
|
+
"1306" => "Canada",
|
25
|
+
"1343" => "Canada",
|
26
|
+
"1403" => "Canada",
|
27
|
+
"1416" => "Canada",
|
28
|
+
"1418" => "Canada",
|
29
|
+
"1438" => "Canada",
|
30
|
+
"1450" => "Canada",
|
31
|
+
"1506" => "Canada",
|
32
|
+
"1514" => "Canada",
|
33
|
+
"1519" => "Canada",
|
34
|
+
"1581" => "Canada",
|
35
|
+
"1587" => "Canada",
|
36
|
+
"1604" => "Canada",
|
37
|
+
"1613" => "Canada",
|
38
|
+
"1647" => "Canada",
|
39
|
+
"1705" => "Canada",
|
40
|
+
"1709" => "Canada",
|
41
|
+
"1778" => "Canada",
|
42
|
+
"1780" => "Canada",
|
43
|
+
"1807" => "Canada",
|
44
|
+
"1819" => "Canada",
|
45
|
+
"1867" => "Canada",
|
46
|
+
"1902" => "Canada",
|
47
|
+
"1905" => "Canada",
|
48
|
+
"1345" => "Cayman Islands",
|
49
|
+
"1767" => "Dominica (Commonwealth of)",
|
50
|
+
"1809" => "Dominican Republic",
|
51
|
+
"1829" => "Dominican Republic",
|
52
|
+
"1473" => "Grenada",
|
53
|
+
"1671" => "Guam",
|
54
|
+
"1876" => "Jamaica",
|
55
|
+
"1664" => "Montserrat",
|
56
|
+
"1670" => "Northern Mariana Islands (Commonwealth of the)",
|
57
|
+
"1869" => "Saint Kitts and Nevis",
|
58
|
+
"1758" => "Saint Lucia",
|
59
|
+
"1784" => "Saint Vincent and the Grenadines",
|
60
|
+
"1868" => "Trinidad and Tobago",
|
61
|
+
"1649" => "Turks and Caicos Islands",
|
62
|
+
"1340" => "United States Virgin Islands"
|
63
|
+
},
|
64
|
+
"20" => "Egypt (Arab Republic of)",
|
65
|
+
"210" => "Spare code",
|
66
|
+
"211" => "Spare code",
|
67
|
+
"212" => "Morocco (Kingdom of)",
|
68
|
+
"213" => "Algeria (People's Democratic Republic of)",
|
69
|
+
"214" => "Spare code",
|
70
|
+
"215" => "Spare code",
|
71
|
+
"216" => "Tunisia",
|
72
|
+
"217" => "Spare code",
|
73
|
+
"218" => "Libya (Socialist People's Libyan Arab Jamahiriya)",
|
74
|
+
"219" => "Spare code",
|
75
|
+
"220" => "Gambia (Republic of the)",
|
76
|
+
"221" => "Senegal (Republic of)",
|
77
|
+
"222" => "Mauritania (Islamic Republic of)",
|
78
|
+
"223" => "Mali (Republic of)",
|
79
|
+
"224" => "Guinea (Republic of)",
|
80
|
+
"225" => "Côte d'Ivoire (Republic of)",
|
81
|
+
"226" => "Burkina Faso",
|
82
|
+
"227" => "Niger (Republic of the)",
|
83
|
+
"228" => "Togolese Republic",
|
84
|
+
"229" => "Benin (Republic of)",
|
85
|
+
"230" => "Mauritius (Republic of)",
|
86
|
+
"231" => "Liberia (Republic of)",
|
87
|
+
"232" => "Sierra Leone",
|
88
|
+
"233" => "Ghana",
|
89
|
+
"234" => "Nigeria (Federal Republic of)",
|
90
|
+
"235" => "Chad (Republic of)",
|
91
|
+
"236" => "Central African Republic",
|
92
|
+
"237" => "Cameroon (Republic of)",
|
93
|
+
"238" => "Cape Verde (Republic of)",
|
94
|
+
"239" => "Sao Tome and Principe (Democratic Republic of)",
|
95
|
+
"240" => "Equatorial Guinea (Republic of)",
|
96
|
+
"241" => "Gabonese Republic",
|
97
|
+
"242" => "Congo (Republic of the)",
|
98
|
+
"243" => "Democratic Republic of the Congo",
|
99
|
+
"244" => "Angola (Republic of)",
|
100
|
+
"245" => "Guinea-Bissau (Republic of)",
|
101
|
+
"246" => "Diego Garcia",
|
102
|
+
"247" => "Ascension",
|
103
|
+
"248" => "Seychelles (Republic of)",
|
104
|
+
"249" => "Sudan (Republic of the)",
|
105
|
+
"250" => "Rwanda (Republic of)",
|
106
|
+
"251" => "Ethiopia (Federal Democratic Republic of)",
|
107
|
+
"252" => "Somali Democratic Republic",
|
108
|
+
"253" => "Djibouti (Republic of)",
|
109
|
+
"254" => "Kenya (Republic of)",
|
110
|
+
"255" => "Tanzania (United Republic of)",
|
111
|
+
"256" => "Uganda (Republic of)",
|
112
|
+
"257" => "Burundi (Republic of)",
|
113
|
+
"258" => "Mozambique (Republic of)",
|
114
|
+
"259" => "Spare code",
|
115
|
+
"260" => "Zambia (Republic of)",
|
116
|
+
"261" => "Madagascar (Republic of)",
|
117
|
+
"262" => "Reunion (French Department of)",
|
118
|
+
"263" => "Zimbabwe (Republic of)",
|
119
|
+
"264" => "Namibia (Republic of)",
|
120
|
+
"265" => "Malawi",
|
121
|
+
"266" => "Lesotho (Kingdom of)",
|
122
|
+
"267" => "Botswana (Republic of)",
|
123
|
+
"268" => "Swaziland (Kingdom of)",
|
124
|
+
"269" => "Comoros (Union of the)",
|
125
|
+
"269" => "Mayotte",
|
126
|
+
"27" => "South Africa (Republic of)",
|
127
|
+
"280" => "Spare code",
|
128
|
+
"281" => "Spare code",
|
129
|
+
"282" => "Spare code",
|
130
|
+
"283" => "Spare code",
|
131
|
+
"284" => "Spare code",
|
132
|
+
"285" => "Spare code",
|
133
|
+
"286" => "Spare code",
|
134
|
+
"287" => "Spare code",
|
135
|
+
"288" => "Spare code",
|
136
|
+
"289" => "Spare code",
|
137
|
+
"290" => "Saint Helena",
|
138
|
+
"291" => "Eritrea",
|
139
|
+
"292" => "Spare code",
|
140
|
+
"293" => "Spare code",
|
141
|
+
"294" => "Spare code",
|
142
|
+
"295" => "Spare code",
|
143
|
+
"296" => "Spare code",
|
144
|
+
"297" => "Aruba",
|
145
|
+
"298" => "Faroe Islands",
|
146
|
+
"299" => "Greenland (Denmark)",
|
147
|
+
"30" => "Greece",
|
148
|
+
"31" => "Netherlands (Kingdom of the)",
|
149
|
+
"32" => "Belgium",
|
150
|
+
"33" => "France",
|
151
|
+
"34" => "Spain",
|
152
|
+
"350" => "Gibraltar",
|
153
|
+
"351" => "Portugal",
|
154
|
+
"352" => "Luxembourg",
|
155
|
+
"353" => "Ireland",
|
156
|
+
"354" => "Iceland",
|
157
|
+
"355" => "Albania (Republic of)",
|
158
|
+
"356" => "Malta",
|
159
|
+
"357" => "Cyprus (Republic of)",
|
160
|
+
"358" => "Finland",
|
161
|
+
"359" => "Bulgaria (Republic of)",
|
162
|
+
"36" => "Hungary (Republic of)",
|
163
|
+
"370" => "Lithuania (Republic of)",
|
164
|
+
"371" => "Latvia (Republic of)",
|
165
|
+
"372" => "Estonia (Republic of)",
|
166
|
+
"373" => "Moldova (Republic of)",
|
167
|
+
"374" => "Armenia (Republic of)",
|
168
|
+
"375" => "Belarus (Republic of)",
|
169
|
+
"376" => "Andorra (Principality of)",
|
170
|
+
"377" => "Monaco (Principality of)",
|
171
|
+
"378" => "San Marino (Republic of)",
|
172
|
+
"379" => "Vatican City State",
|
173
|
+
"380" => "Ukraine",
|
174
|
+
"381" => "Serbia and Montenegro",
|
175
|
+
"382" => "Spare code",
|
176
|
+
"383" => "Spare code",
|
177
|
+
"384" => "Spare code",
|
178
|
+
"385" => "Croatia (Republic of)",
|
179
|
+
"386" => "Slovenia (Republic of)",
|
180
|
+
"387" => "Bosnia and Herzegovina",
|
181
|
+
"388" => "Group of countries, shared code",
|
182
|
+
"389" => "The Former Yugoslav Republic of Macedonia",
|
183
|
+
"39" => "Italy",
|
184
|
+
"39" => "Vatican City State",
|
185
|
+
"40" => "Romania",
|
186
|
+
"41" => "Switzerland (Confederation of)",
|
187
|
+
"420" => "Czech Republic",
|
188
|
+
"421" => "Slovak Republic",
|
189
|
+
"422" => "Spare code",
|
190
|
+
"423" => "Liechtenstein (Principality of)",
|
191
|
+
"424" => "Spare code",
|
192
|
+
"425" => "Spare code",
|
193
|
+
"426" => "Spare code",
|
194
|
+
"427" => "Spare code",
|
195
|
+
"428" => "Spare code",
|
196
|
+
"429" => "Spare code",
|
197
|
+
"43" => "Austria",
|
198
|
+
"44" => "United Kingdom of Great Britain and Northern Ireland",
|
199
|
+
"45" => "Denmark",
|
200
|
+
"46" => "Sweden",
|
201
|
+
"47" => "Norway",
|
202
|
+
"48" => "Poland (Republic of)",
|
203
|
+
"49" => "Germany (Federal Republic of)",
|
204
|
+
"500" => "Falkland Islands (Malvinas)",
|
205
|
+
"501" => "Belize",
|
206
|
+
"502" => "Guatemala (Republic of)",
|
207
|
+
"503" => "El Salvador (Republic of)",
|
208
|
+
"504" => "Honduras (Republic of)",
|
209
|
+
"505" => "Nicaragua",
|
210
|
+
"506" => "Costa Rica",
|
211
|
+
"507" => "Panama (Republic of)",
|
212
|
+
"508" => "Saint Pierre and Miquelon (Collectivité territoriale de la République française)",
|
213
|
+
"509" => "Haiti (Republic of)",
|
214
|
+
"51" => "Peru",
|
215
|
+
"52" => "Mexico",
|
216
|
+
"53" => "Cuba",
|
217
|
+
"54" => "Argentine Republic",
|
218
|
+
"55" => "Brazil (Federative Republic of)",
|
219
|
+
"56" => "Chile",
|
220
|
+
"57" => "Colombia (Republic of)",
|
221
|
+
"58" => "Venezuela (Bolivarian Republic of)",
|
222
|
+
"590" => "Guadeloupe (French Department of)",
|
223
|
+
"591" => "Bolivia (Republic of)",
|
224
|
+
"592" => "Guyana",
|
225
|
+
"593" => "Ecuador",
|
226
|
+
"594" => "French Guiana (French Department of)",
|
227
|
+
"595" => "Paraguay (Republic of)",
|
228
|
+
"596" => "Martinique (French Department of)",
|
229
|
+
"597" => "Suriname (Republic of)",
|
230
|
+
"598" => "Uruguay (Eastern Republic of)",
|
231
|
+
"599" => "Netherlands Antilles",
|
232
|
+
"60" => "Malaysia",
|
233
|
+
"61" => "Australia",
|
234
|
+
"62" => "Indonesia (Republic of)",
|
235
|
+
"63" => "Philippines (Republic of the)",
|
236
|
+
"64" => "New Zealand",
|
237
|
+
"65" => "Singapore (Republic of)",
|
238
|
+
"66" => "Thailand",
|
239
|
+
"670" => "Democratic Republic of Timor-Leste",
|
240
|
+
"671" => "Spare code",
|
241
|
+
"672" => "Australian External Territories",
|
242
|
+
"673" => "Brunei Darussalam",
|
243
|
+
"674" => "Nauru (Republic of)",
|
244
|
+
"675" => "Papua New Guinea",
|
245
|
+
"676" => "Tonga (Kingdom of)",
|
246
|
+
"677" => "Solomon Islands",
|
247
|
+
"678" => "Vanuatu (Republic of)",
|
248
|
+
"679" => "Fiji (Republic of)",
|
249
|
+
"680" => "Palau (Republic of)",
|
250
|
+
"681" => "Wallis and Futuna (Territoire français d'outre-mer)",
|
251
|
+
"682" => "Cook Islands",
|
252
|
+
"683" => "Niue",
|
253
|
+
"684" => "Spare code",
|
254
|
+
"685" => "Samoa (Independent State of)",
|
255
|
+
"686" => "Kiribati (Republic of)",
|
256
|
+
"687" => "New Caledonia (Territoire français d'outre-mer)",
|
257
|
+
"688" => "Tuvalu",
|
258
|
+
"689" => "French Polynesia (Territoire français d'outre-mer)",
|
259
|
+
"690" => "Tokelau",
|
260
|
+
"691" => "Micronesia (Federated States of)",
|
261
|
+
"692" => "Marshall Islands (Republic of the)",
|
262
|
+
"693" => "Spare code",
|
263
|
+
"694" => "Spare code",
|
264
|
+
"695" => "Spare code",
|
265
|
+
"696" => "Spare code",
|
266
|
+
"697" => "Spare code",
|
267
|
+
"698" => "Spare code",
|
268
|
+
"699" => "Spare code",
|
269
|
+
"7" => [
|
270
|
+
"Kazakhstan (Republic of)",
|
271
|
+
"Russian Federation"
|
272
|
+
],
|
273
|
+
"800" => "International Freephone Service",
|
274
|
+
"801" => "Spare code",
|
275
|
+
"802" => "Spare code",
|
276
|
+
"803" => "Spare code",
|
277
|
+
"804" => "Spare code",
|
278
|
+
"805" => "Spare code",
|
279
|
+
"806" => "Spare code",
|
280
|
+
"807" => "Spare code",
|
281
|
+
"808" => "International Shared Cost Service (ISCS)",
|
282
|
+
"809" => "Spare code",
|
283
|
+
"81" => "Japan",
|
284
|
+
"82" => "Korea (Republic of)",
|
285
|
+
"830" => "Spare code",
|
286
|
+
"831" => "Spare code",
|
287
|
+
"832" => "Spare code",
|
288
|
+
"833" => "Spare code",
|
289
|
+
"834" => "Spare code",
|
290
|
+
"835" => "Spare code",
|
291
|
+
"836" => "Spare code",
|
292
|
+
"837" => "Spare code",
|
293
|
+
"838" => "Spare code",
|
294
|
+
"839" => "Spare code",
|
295
|
+
"84" => "Viet Nam (Socialist Republic of)",
|
296
|
+
"850" => "Democratic People's Republic of Korea",
|
297
|
+
"851" => "Spare code",
|
298
|
+
"852" => "Hong Kong, China",
|
299
|
+
"853" => "Macao, China",
|
300
|
+
"854" => "Spare code",
|
301
|
+
"855" => "Cambodia (Kingdom of)",
|
302
|
+
"856" => "Lao People's Democratic Republic",
|
303
|
+
"857" => "Spare code",
|
304
|
+
"858" => "Spare code",
|
305
|
+
"859" => "Spare code",
|
306
|
+
"86" => "China (People's Republic of)",
|
307
|
+
"870" => "Inmarsat SNAC",
|
308
|
+
"871" => "Inmarsat (Atlantic Ocean-East)",
|
309
|
+
"872" => "Inmarsat (Pacific Ocean)",
|
310
|
+
"873" => "Inmarsat (Indian Ocean)",
|
311
|
+
"874" => "Inmarsat (Atlantic Ocean-West)",
|
312
|
+
"875" => "Reserved - Maritime Mobile Service Applications",
|
313
|
+
"876" => "Reserved - Maritime Mobile Service Applications",
|
314
|
+
"877" => "Reserved - Maritime Mobile Service Applications",
|
315
|
+
"878" => "Universal Personal Telecommunication Service (UPT)",
|
316
|
+
"879" => "Reserved for national non-commercial purposes",
|
317
|
+
"880" => "Bangladesh (People's Republic of)",
|
318
|
+
"881" => "International Mobile, shared code",
|
319
|
+
"882" => "International Networks, shared code",
|
320
|
+
"883" => "Spare code",
|
321
|
+
"884" => "Spare code",
|
322
|
+
"885" => "Spare code",
|
323
|
+
"886" => "Reserved",
|
324
|
+
"887" => "Spare code",
|
325
|
+
"888" => "Reserved for future global service",
|
326
|
+
"889" => "Spare code",
|
327
|
+
"890" => "Spare code",
|
328
|
+
"891" => "Spare code",
|
329
|
+
"892" => "Spare code",
|
330
|
+
"893" => "Spare code",
|
331
|
+
"894" => "Spare code",
|
332
|
+
"895" => "Spare code",
|
333
|
+
"896" => "Spare code",
|
334
|
+
"897" => "Spare code",
|
335
|
+
"898" => "Spare code",
|
336
|
+
"899" => "Spare code",
|
337
|
+
"90" => "Turkey",
|
338
|
+
"91" => "India (Republic of)",
|
339
|
+
"92" => "Pakistan (Islamic Republic of)",
|
340
|
+
"93" => "Afghanistan",
|
341
|
+
"94" => "Sri Lanka (Democratic Socialist Republic of)",
|
342
|
+
"95" => "Myanmar (Union of)",
|
343
|
+
"960" => "Maldives (Republic of)",
|
344
|
+
"961" => "Lebanon",
|
345
|
+
"962" => "Jordan (Hashemite Kingdom of)",
|
346
|
+
"963" => "Syrian Arab Republic",
|
347
|
+
"964" => "Iraq (Republic of)",
|
348
|
+
"965" => "Kuwait (State of)",
|
349
|
+
"966" => "Saudi Arabia (Kingdom of)",
|
350
|
+
"967" => "Yemen (Republic of)",
|
351
|
+
"968" => "Oman (Sultanate of)",
|
352
|
+
"969" => "Reserved - reservation currently under investigation",
|
353
|
+
"970" => "Reserved",
|
354
|
+
"971" => "United Arab Emirates",
|
355
|
+
"972" => "Israel (State of)",
|
356
|
+
"973" => "Bahrain (Kingdom of)",
|
357
|
+
"974" => "Qatar (State of)",
|
358
|
+
"975" => "Bhutan (Kingdom of)",
|
359
|
+
"976" => "Mongolia",
|
360
|
+
"977" => "Nepal",
|
361
|
+
"978" => "Spare code",
|
362
|
+
"979" => "International Premium Rate Service (IPRS)",
|
363
|
+
"98" => "Iran (Islamic Republic of)",
|
364
|
+
"990" => "Spare code",
|
365
|
+
"991" => "Trial of a proposed new international telecommunication public correspondence",
|
366
|
+
"992" => "Tajikistan (Republic of)",
|
367
|
+
"993" => "Turkmenistan",
|
368
|
+
"994" => "Azerbaijani Republic",
|
369
|
+
"995" => "Georgia"
|
370
|
+
}
|
371
|
+
|
372
|
+
def self.list
|
373
|
+
@@CODE_LIST
|
374
|
+
end
|
375
|
+
|
376
|
+
# returns an array of hashes:
|
377
|
+
# ItuCodes.find(995)
|
378
|
+
# => [{"995"=>"Georgia"}]
|
379
|
+
# ItuCodes.find("france")
|
380
|
+
# => [{"33"=>"France"}]
|
381
|
+
# ItuCodes.find("stan")
|
382
|
+
# => [{"992" => "Tajikistan (Republic of)"},
|
383
|
+
# => {"993" => "Turkmenistan"},
|
384
|
+
# => {"7" => ["Kazakhstan (Republic of)", "Russian Federation"]},
|
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
|
390
|
+
find_by_name(code_or_name)
|
391
|
+
else
|
392
|
+
find_by_code(code_or_name)
|
393
|
+
end
|
394
|
+
end
|
395
|
+
|
396
|
+
def self.find_by_code(code)
|
397
|
+
@@CODE_LIST.find_all { |k,v| k == code.to_s }.map do |pair|
|
398
|
+
Hash[*pair]
|
399
|
+
end
|
400
|
+
end
|
401
|
+
|
402
|
+
def self.find_by_name(name)
|
403
|
+
@@CODE_LIST.find_all { |k,v| v.to_s.downcase.include? name.downcase }.map do |pair|
|
404
|
+
Hash[*pair]
|
405
|
+
end
|
406
|
+
end
|
407
|
+
|
408
|
+
def self.valid_code?(some_code)
|
409
|
+
some_code = some_code.to_s unless some_code.respond_to? :length
|
410
|
+
if some_code[0,1] == "1" and some_code.length >= 4
|
411
|
+
@@CODE_LIST['1'].key? some_code
|
412
|
+
else
|
413
|
+
@@CODE_LIST.key? some_code
|
414
|
+
end
|
415
|
+
end
|
416
|
+
|
417
|
+
# parse a destination code (probably with area code) to find the ITU code
|
418
|
+
# ex: parse_code(1818) => 1
|
419
|
+
def self.parse_code(some_code)
|
420
|
+
some_code = some_code.to_s unless some_code.respond_to? :length
|
421
|
+
|
422
|
+
# North American codes are a headache:
|
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
|
445
|
+
end
|
446
|
+
end
|
447
|
+
|
448
|
+
def self.compatriots?(some, other)
|
449
|
+
returner = false
|
450
|
+
|
451
|
+
some_country_code = parse_code some
|
452
|
+
other_country_code = parse_code other
|
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
|
458
|
+
end
|
459
|
+
|
460
|
+
returner
|
461
|
+
end
|
462
|
+
|
463
|
+
def self.american?(some_code)
|
464
|
+
parse_code(some_code) == "1"
|
465
|
+
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
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'itu_codes.rb'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class ItuCodesTest < Test::Unit::TestCase
|
5
|
+
def test_valid_code?
|
6
|
+
american = "1"
|
7
|
+
newyorker = "1212"
|
8
|
+
russian = "7"
|
9
|
+
alien = "alksjlkknm"
|
10
|
+
|
11
|
+
assert ItuCodes.valid_code?(american)
|
12
|
+
assert ItuCodes.valid_code?(russian)
|
13
|
+
|
14
|
+
assert ! ItuCodes.valid_code?(newyorker) # 1212 is not a country code!
|
15
|
+
assert ! ItuCodes.valid_code?(alien)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_parse_code
|
19
|
+
american = "1"
|
20
|
+
newyorker = "1212"
|
21
|
+
russian = "7"
|
22
|
+
alien = "alksjlkknm"
|
23
|
+
|
24
|
+
assert_equal american, ItuCodes.parse_code(american)
|
25
|
+
assert_equal american, ItuCodes.parse_code(newyorker)
|
26
|
+
|
27
|
+
assert_not_equal russian, ItuCodes.parse_code(newyorker)
|
28
|
+
assert_not_equal russian, ItuCodes.parse_code(alien)
|
29
|
+
|
30
|
+
assert_not_equal alien, ItuCodes.parse_code(alien)
|
31
|
+
|
32
|
+
assert_nil ItuCodes.parse_code(alien)
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def test_compatriots?
|
37
|
+
american = "1"
|
38
|
+
newyorker = "1212"
|
39
|
+
angeleno = "1818"
|
40
|
+
russian = "7"
|
41
|
+
alien = "alksjlkknm"
|
42
|
+
|
43
|
+
assert ItuCodes.compatriots?(newyorker, angeleno)
|
44
|
+
assert ItuCodes.compatriots?(newyorker, american)
|
45
|
+
|
46
|
+
assert ! ItuCodes.compatriots?(newyorker, russian)
|
47
|
+
assert ! ItuCodes.compatriots?(american, russian )
|
48
|
+
|
49
|
+
assert nil == ItuCodes.compatriots?(american, alien)
|
50
|
+
assert nil == ItuCodes.compatriots?(alien, alien)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_find
|
54
|
+
assert_equal( [{"995" => "Georgia"}], ItuCodes.find("Georgia") )
|
55
|
+
assert_equal( [{"995" => "Georgia"}], ItuCodes.find(995) )
|
56
|
+
assert_equal( [{"995" => "Georgia"}], ItuCodes.find("995") )
|
57
|
+
assert_equal( [], ItuCodes.find("12345678") )
|
58
|
+
assert_equal( [], ItuCodes.find("someverylongandnonterritorialstring") )
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: itu_codes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.2"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mani Tadayon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-14 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.12.1
|
24
|
+
version:
|
25
|
+
description: Easy to use tools to look up and parse international calling codes.
|
26
|
+
email:
|
27
|
+
- mta5@me.com
|
28
|
+
executables: []
|
29
|
+
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files:
|
33
|
+
- History.txt
|
34
|
+
- Manifest.txt
|
35
|
+
- README.txt
|
36
|
+
files:
|
37
|
+
- History.txt
|
38
|
+
- Manifest.txt
|
39
|
+
- README.txt
|
40
|
+
- Rakefile
|
41
|
+
- lib/itu_codes.rb
|
42
|
+
- test/itu_codes_test.rb
|
43
|
+
has_rdoc: true
|
44
|
+
homepage: http://rubyforge.org/projects/itu-codes
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options:
|
47
|
+
- --main
|
48
|
+
- README.txt
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
version:
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project: bowser_senior
|
66
|
+
rubygems_version: 1.3.1
|
67
|
+
signing_key:
|
68
|
+
specification_version: 2
|
69
|
+
summary: Easy to use tools to look up and parse international calling codes.
|
70
|
+
test_files: []
|
71
|
+
|