phony 2.19.2 → 2.20.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.textile +5 -1
- data/lib/phony/countries/brazil.rb +2 -2
- data/lib/phony/countries/italy.rb +34 -16
- data/lib/phony/countries/japan.rb +51 -2
- data/lib/phony/countries/libya.rb +1 -1
- data/lib/phony/countries/taiwan.rb +1 -0
- data/lib/phony/countries/vietnam.rb +3 -0
- data/lib/phony/countries.rb +72 -36
- data/lib/phony/country.rb +4 -0
- data/lib/phony/country_codes.rb +14 -1
- data/lib/phony/local_splitters/fixed.rb +2 -0
- data/lib/phony/national_splitters/none.rb +1 -3
- data/spec/functional/config_spec.rb +5 -5
- data/spec/functional/plausibility_spec.rb +71 -17
- data/spec/lib/phony/countries_spec.rb +42 -15
- data/spec/lib/phony/country_codes_spec.rb +78 -55
- data/spec/lib/phony/country_spec.rb +13 -13
- data/spec/lib/phony/dsl_spec.rb +6 -2
- data/spec/lib/phony/local_splitters/regex_spec.rb +12 -15
- data/spec/lib/phony/national_code_spec.rb +15 -45
- data/spec/lib/phony/national_splitters/fixed_spec.rb +12 -16
- data/spec/lib/phony/national_splitters/none_spec.rb +3 -3
- data/spec/lib/phony/national_splitters/variable_spec.rb +9 -13
- data/spec/lib/phony/vanity_spec.rb +4 -4
- metadata +15 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b309483112eea98930ed42b246d6df922d06e268212e696aa23c28035956f65c
|
4
|
+
data.tar.gz: 1ee4fbc7968e7bbc3d90ac062635c2cc810d9aa3890103aeeb03fd13dbddedc5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76d9ad6a66e4df3eecdd12338ac140f3f93eb8fde71975c01035373f1f4074a9590d32251f50ef0207949f23561cc9b72ae83b1d3960148c23cb3156c9c172ad
|
7
|
+
data.tar.gz: a4e5c31d362c9afbca54e4fd7248569b008d405ea4b2ea52891f3f4b84cc01514f982e79a80a619886cb57f5c142c55de9342f8c1af4a7df1f9893ea1182dfd7
|
data/README.textile
CHANGED
@@ -104,7 +104,11 @@ For example, when just loading the NANP CC, the retained memory usage is ~63kB.
|
|
104
104
|
|
105
105
|
h2. List of Handled Countries
|
106
106
|
|
107
|
-
Mildly unmaintained list: Abhas, Afghan, Algerian, Argentina, Austrian, Australian, Azerbaijani, Belgian, Brazilian, Cambodian, Chilean, Chinese, Croatian, Cuban, Cypriot, Czech, Danish, Dutch, Egyptian, El Salvadorian, Estonian, French, German, Ghanan, Gibraltar, Greek, Haiti, Hong Kong, Hungarian, Indian, Iran, Irish, Israel, Italian, Japanese, Kazakh, Liberian, Lithuanian, Luxembourgian, Malaysian, Malta, Mexican, Monaco, Morocco, New Zealand, Nigerian, Norwegian, Peruvian, Polish, Romanian, Russian, Rwandan, Seychelles, Singapore, Slovakian, South African, South Korean, South Osetian, Spanish, Sri Lankan, Sudan, Swedish, Swiss, Thailand, Tunisian, Turkish, Liechtenstein, UK, US, Venezuelan, Vietnamese, and Zambian numbers.
|
107
|
+
Mildly unmaintained list: Abhas, Afghan, Algerian, Argentina, Austrian, Australian, Azerbaijani, Belgian, Brazilian, Cambodian, Chilean, Chinese, Croatian, Cuban, Cypriot, Czech, Danish, Dutch, Egyptian, El Salvadorian, Estonian, French, German, Ghanan, Gibraltar, Greek, Haiti, Hong Kong, Hungarian, Indian, Iran, Irish, Israel, Italian, Japanese, Kazakh, Liberian, Lithuanian, Luxembourgian, Malaysian, Malta, Mauritian, Mexican, Monaco, Morocco, New Zealand, Nigerian, Norwegian, Peruvian, Polish, Romanian, Russian, Rwandan, Seychelles, Singapore, Slovakian, South African, South Korean, South Osetian, Spanish, Sri Lankan, Sudan, Swedish, Swiss, Thailand, Tunisian, Turkish, Liechtenstein, UK, US, Venezuelan, Vietnamese, and Zambian numbers.
|
108
|
+
|
109
|
+
h2. Proud Sponsors
|
110
|
+
|
111
|
+
* Renuo AG (July 22 –): "Github":https://github.com/renuo, "Homepage":https://www.renuo.ch
|
108
112
|
|
109
113
|
h2. License
|
110
114
|
|
@@ -4,7 +4,7 @@
|
|
4
4
|
#
|
5
5
|
#
|
6
6
|
# NDC Reference
|
7
|
-
#
|
7
|
+
# https://www.gov.br/anatel/pt-br/regulado/numeracao/plano-de-numeracao-brasileiro
|
8
8
|
|
9
9
|
# 11 #Sao Paulo
|
10
10
|
# 12 #Sao Paulo
|
@@ -99,7 +99,7 @@ special_numbers_4 = %w{ 3003 4003 4004 4020 }
|
|
99
99
|
Phony.define do
|
100
100
|
country '55',
|
101
101
|
match(/^#{ndcs}9\d{8}$/) >> split(5,4) |
|
102
|
-
match(/^#{ndcs}\d{
|
102
|
+
match(/^#{ndcs}[2-5]\d{7}$/) >> split(4,4) |
|
103
103
|
one_of(special_numbers_3_4) >> split(3,4) |
|
104
104
|
one_of(special_numbers_4) >> split(4) |
|
105
105
|
one_of(service) >> split(3) |
|
@@ -3,14 +3,14 @@
|
|
3
3
|
# Italian phone numbers.
|
4
4
|
#
|
5
5
|
# http://en.wikipedia.org/wiki/Telephone_numbers_in_Italy
|
6
|
-
#
|
6
|
+
# https://www.itu.int/dms_pub/itu-t/oth/02/02/T020200006B0001PDFE.pdf
|
7
7
|
|
8
|
-
|
8
|
+
ndcs_1digit = [
|
9
9
|
'02', # Milan
|
10
10
|
'06', # Rome (including State of Vatican City) and Aprilia
|
11
11
|
]
|
12
12
|
|
13
|
-
|
13
|
+
ndcs_2digit = [
|
14
14
|
'010', # Genoa
|
15
15
|
'011', # Turin
|
16
16
|
'015', # Biella
|
@@ -42,7 +42,7 @@ ndcs_3digit = [
|
|
42
42
|
'099', # Taranto
|
43
43
|
]
|
44
44
|
|
45
|
-
|
45
|
+
ndcs_3digit = [
|
46
46
|
'0121', # Pinerolo
|
47
47
|
'0122', # Sestrieres, Bardonecchia and other Susa Valley mountain resorts
|
48
48
|
'0123', # Lanzo Torinese
|
@@ -256,7 +256,8 @@ ndcs_4digit = [
|
|
256
256
|
# but this was not frozen so easily.
|
257
257
|
mobile = %w(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 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399)
|
258
258
|
|
259
|
-
|
259
|
+
# Not exhaustive.
|
260
|
+
service = [
|
260
261
|
'112',
|
261
262
|
'113',
|
262
263
|
'115',
|
@@ -268,21 +269,38 @@ service = [ # Not exhaustive.
|
|
268
269
|
'1530'
|
269
270
|
]
|
270
271
|
|
272
|
+
# Not exhaustive. Unused below - just for info purposes.
|
273
|
+
free_of_charge_services = [
|
274
|
+
'800',
|
275
|
+
'803'
|
276
|
+
]
|
277
|
+
|
271
278
|
Phony.define do
|
279
|
+
# Note: The 0 does not count towards NDC number length.
|
272
280
|
country '39', trunk('', normalize: false) |
|
273
281
|
one_of(*service) >> split(3,3) |
|
274
282
|
one_of(*mobile) >> split(3,4,-1..1) |
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
283
|
+
match(/^(800)\d{6}$/) >> split(6) | # 3-6, Special handling for 800 numbers.
|
284
|
+
match(/^(803)\d{3}$/) >> split(3) | # 3-3, Special handling for 803 numbers.
|
285
|
+
one_of(*ndcs_1digit) >> matched_split(
|
286
|
+
/\A\d{5}\z/ => [5],
|
287
|
+
/\A\d{6}\z/ => [4,2],
|
288
|
+
/\A\d{7}\z/ => [4,3],
|
289
|
+
/\A\d{8}\z/ => [4,4],
|
290
|
+
/\A\d{9}\z/ => [4,5]
|
281
291
|
) |
|
282
|
-
one_of(*
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
292
|
+
one_of(*ndcs_2digit) >> matched_split(
|
293
|
+
/\A\d{4}\z/ => [4],
|
294
|
+
/\A\d{5}\z/ => [5],
|
295
|
+
/\A\d{6}\z/ => [6],
|
296
|
+
/\A\d{7}\z/ => [7],
|
297
|
+
/\A\d{8}\z/ => [8]
|
298
|
+
) |
|
299
|
+
one_of(*ndcs_3digit) >> matched_split(
|
300
|
+
/\A\d{4}\z/ => [4],
|
301
|
+
/\A1\d{5}\z/ => [6],
|
302
|
+
/\A1\d{6}\z/ => [7],
|
303
|
+
/\A[^1]\d{4}\z/ => [5],
|
304
|
+
/\A[^1]\d{5}\z/ => [3,3]
|
287
305
|
)
|
288
306
|
end
|
@@ -403,7 +403,56 @@ Phony.define do
|
|
403
403
|
country '81',
|
404
404
|
trunk('0', normalize: true, format: true, split: true) |
|
405
405
|
one_of(%w(20 50 60 70 90)) >> split(4,4) | # mobile, VoIP telephony
|
406
|
+
match(/\A(597)9[0178]\d+\z/) >> split(2,4) |
|
406
407
|
one_of(ndcs_with_5_subscriber_numbers) >> split(1,4) |
|
408
|
+
match(/\A(4)70[019]\d+\z/) >> split(4,4) |
|
409
|
+
match(/\A(4)71\d+\z/) >> split(4,4) |
|
410
|
+
match(/\A(4)20\d+\z/) >> split(4,4) |
|
411
|
+
match(/\A(4)29[02-69]\d+\z/) >> split(4,4) |
|
412
|
+
match(/\A(15)4[018]\d+\z/) >> split(3,4) |
|
413
|
+
match(/\A(22)3[014-9]\d+\z/) >> split(3,4) |
|
414
|
+
match(/\A(25)[04][01]\d+\z/) >> split(3,4) |
|
415
|
+
match(/\A(25)5[0-69]\d+\z/) >> split(3,4) |
|
416
|
+
match(/\A(25)[68][01]\d+\z/) >> split(3,4) |
|
417
|
+
match(/\A(25)7[015-9]\d+\z/) >> split(3,4) |
|
418
|
+
match(/\A(25)917\d+\z/) >> split(3,4) |
|
419
|
+
match(/\A(25)999\d+\z/) >> split(3,4) |
|
420
|
+
match(/\A(26)4[016-9]\d+\z/) >> split(3,4) |
|
421
|
+
match(/\A(28)3[0134]\d+\z/) >> split(3,4) |
|
422
|
+
match(/\A(28)9[0-5]\d+\z/) >> split(3,4) |
|
423
|
+
match(/\A(29)17\d+\z/) >> split(3,4) |
|
424
|
+
match(/\A(29)3[015-9]\d+\z/) >> split(3,4) |
|
425
|
+
match(/\A(42)21\d+\z/) >> split(3,4) |
|
426
|
+
match(/\A(42)8[01456]\d+\z/) >> split(3,4) |
|
427
|
+
match(/\A(47)5[019]\d+\z/) >> split(3,4) |
|
428
|
+
match(/\A(47)9[019]\d+\z/) >> split(3,4) |
|
429
|
+
match(/\A(59)8[019]\d+\z/) >> split(3,4) |
|
430
|
+
match(/\A(59)9[01]\d+\z/) >> split(3,4) |
|
431
|
+
match(/\A(79)4[0-59]\d+\z/) >> split(3,4) |
|
432
|
+
match(/\A(79)5[01569]\d+\z/) >> split(3,4) |
|
433
|
+
match(/\A(79)6[0167]\d+\z/) >> split(3,4) |
|
434
|
+
match(/\A(82)4[0-39]\d+\z/) >> split(3,4) |
|
435
|
+
match(/\A(82)9[019]\d+\z/) >> split(3,4) |
|
436
|
+
match(/\A(82)92[1-9]\d+\z/) >> split(3,4) |
|
437
|
+
match(/\A(82)94[1-3]\d+\z/) >> split(3,4) |
|
438
|
+
match(/\A(82)96[0-47-9]\d+\z/) >> split(3,4) |
|
439
|
+
match(/\A(82)965[01346-9]\d+\z/) >> split(3,4) |
|
440
|
+
match(/\A(82)966[1-9]\d+\z/) >> split(3,4) |
|
441
|
+
match(/\A(83)76[6-8]\d+\z/) >> split(3,4) |
|
442
|
+
match(/\A(83)7[01789]\d+\z/) >> split(3,4) |
|
443
|
+
match(/\A(83)8[01]\d+\z/) >> split(3,4) |
|
444
|
+
match(/\A(86)36[23]\d+\z/) >> split(3,4) |
|
445
|
+
match(/\A(86)5[0-389]\d+\z/) >> split(3,4) |
|
446
|
+
match(/\A(86)55[23]\d+\z/) >> split(3,4) |
|
447
|
+
match(/\A(86)[01]\d+\z/) >> split(3,4) |
|
448
|
+
match(/\A(86)9[178]\d+\z/) >> split(3,4) |
|
449
|
+
match(/\A(86)72\d+\z/) >> split(3,4) |
|
450
|
+
match(/\A(86)8[019]\d+\z/) >> split(3,4) |
|
451
|
+
match(/\A(86)9[0145]\d+\z/) >> split(3,4) |
|
452
|
+
match(/\A(86)99[014-9]\d+\z/) >> split(3,4) |
|
453
|
+
match(/\A(99)331\d+\z/) >> split(3,4) |
|
454
|
+
match(/\A(99)34[357]\d+\z/) >> split(3,4) |
|
455
|
+
match(/\A(99)4[0178]\d+\z/) >> split(3,4) |
|
407
456
|
one_of(ndcs_with_6_subscriber_numbers) >> split(2,4) |
|
408
457
|
one_of(%w(120)) >> split(3,3) | # freephone
|
409
458
|
one_of(%w(800)) >> split(3,4) | # freephone
|
@@ -414,6 +463,6 @@ Phony.define do
|
|
414
463
|
one_of(ndcs_with_8_subscriber_numbers) >> split(4,4) |
|
415
464
|
# TODO: 91(NDC) N(S)N length: 5-13 - Non-geographic number (Direct subscriber telephone service (legacy))
|
416
465
|
fixed(2) >> split(4,4),
|
417
|
-
:
|
418
|
-
:
|
466
|
+
local_space: :-,
|
467
|
+
space: :-
|
419
468
|
end
|
@@ -111,6 +111,6 @@ Phony.define do
|
|
111
111
|
one_of(ndcs_with_5_subscriber_numbers) >> split(3,2) |
|
112
112
|
one_of(ndcs_with_6_subscriber_numbers) >> split(3,3) |
|
113
113
|
one_of(ndcs_with_7_subscriber_numbers) >> split(4,3) |
|
114
|
-
one_of(%w(91 92)) >> split(4,3) | # mobile
|
114
|
+
one_of(%w(91 92 94 95)) >> split(4,3) | # mobile
|
115
115
|
fixed(2) >> split(3,3)
|
116
116
|
end
|
@@ -11,6 +11,7 @@ Phony.define do
|
|
11
11
|
match(/\A(836)\d{5}\z/) >> split(1,4) | # 馬祖, start with 0836, plus 5 digits
|
12
12
|
match(/\A(82)\d{6}\z/) >> split(2,4) | # 金門, start with 082, plus 6 digits
|
13
13
|
match(/\A(89)\d{6}\z/) >> split(2,4) | # 臺東, start with 089, plus 6 digits
|
14
|
+
match(/\A(80\d)\d{6}\z/)>> split(3,4) | # Toll-free number
|
14
15
|
match(/\A(8)\d{7}\z/) >> split(3,4) | # 屏東, start with 08, plus 7 digits
|
15
16
|
match(/\A(49)\d{7}\z/) >> split(3,4) | # 南投, start with 049, plus 7 digits
|
16
17
|
one_of(%w(4)) >> matched_split(
|
@@ -127,6 +127,9 @@ Phony.define do
|
|
127
127
|
one_of(ndcs_with_7_subscriber_digits) >> split(3,4) |
|
128
128
|
one_of(ndcs_with_8_subscriber_digits) >> split(4,4) |
|
129
129
|
one_of(mobile_with_trunk) >> split(5..8)|
|
130
|
+
one_of('1900') >> matched_split(
|
131
|
+
/\A\d{4}\z/ => [4],
|
132
|
+
/\A\d{6}\z/ => [6]) | # Premium rate
|
130
133
|
# Govt reserved
|
131
134
|
fixed(80) >> split(5) |
|
132
135
|
fixed(69) >> split(1,5)
|
data/lib/phony/countries.rb
CHANGED
@@ -96,15 +96,16 @@ Phony.define do
|
|
96
96
|
# Belgium.
|
97
97
|
#
|
98
98
|
# http://en.wikipedia.org/wiki/Telephone_numbers_in_Belgium
|
99
|
+
# https://www.bipt.be/operators/publication/national-numbering-plan
|
99
100
|
#
|
100
101
|
country '32', trunk('0') |
|
101
|
-
match(/^(7[08])\d+$/)
|
102
|
-
match(/^(800|90\d)\d+$/)
|
103
|
-
match(/^(46[
|
104
|
-
match(/^(4[789]\d)\d{6}$/)
|
105
|
-
match(/^(45[56])\d{6}$/)
|
106
|
-
one_of('2','3','4','9')
|
107
|
-
fixed(2)
|
102
|
+
match(/^(7[08])\d+$/) >> split(3,3) | # Premium and national rate Services
|
103
|
+
match(/^(800|90\d)\d+$/) >> split(2,3) | # Toll free service and premium numbers
|
104
|
+
match(/^(46[056789])\d{6}$/) >> split(2,2,2) | # Mobile (Lycamobile, Telenet, Join Experience, Proximus 0460)
|
105
|
+
match(/^(4[789]\d)\d{6}$/) >> split(2,2,2) | # Mobile
|
106
|
+
match(/^(45[56])\d{6}$/) >> split(2,2,2) | # Mobile Vikings and Voo
|
107
|
+
one_of('2','3','4','9') >> split(3,2,2) | # Short NDCs
|
108
|
+
fixed(2) >> split(2,2,2) # 2-digit NDCs
|
108
109
|
|
109
110
|
# France.
|
110
111
|
#
|
@@ -154,6 +155,7 @@ Phony.define do
|
|
154
155
|
#
|
155
156
|
country '41',
|
156
157
|
trunk('0', normalize: true) |
|
158
|
+
match(/^(860)\d+$/) >> split(2, 3, 2, 2) | # Voice Mail access
|
157
159
|
match(/^(8(?:00|4[0248]))\d+$/) >> split(3,3) | # Freecall/Shared Cost
|
158
160
|
match(/^(90[016])\d+$/) >> split(3,3) | # Business
|
159
161
|
fixed(2) >> split(3,2,2)
|
@@ -230,6 +232,7 @@ Phony.define do
|
|
230
232
|
# http://www.itu.int/oth/T020200002C/en
|
231
233
|
country '57',
|
232
234
|
match(/\A(3\d\d)\d+\z/) >> split(3,4) | # mobile (300 310 311 312 313 315 316)
|
235
|
+
match(/\A(60\d)\d+\z/) >> split(3,4) |
|
233
236
|
fixed(1) >> split(3,4)
|
234
237
|
|
235
238
|
# Venezuela (Bolivarian Republic of)
|
@@ -360,12 +363,29 @@ Phony.define do
|
|
360
363
|
trunk('', :normalize => false) |
|
361
364
|
fixed(2) >> split(2,2,2,2)
|
362
365
|
|
363
|
-
|
366
|
+
# Burkina Faso
|
367
|
+
# http://www.wtng.info/wtng-226-bf.html
|
368
|
+
# https://en.wikipedia.org/wiki/Telephone_numbers_in_Burkina_Faso
|
369
|
+
#
|
370
|
+
# There is no trunk code for this country and several of the mobile prefixes start with 0
|
371
|
+
country '226',
|
372
|
+
trunk('', normalize: false) |
|
373
|
+
none >> split(2,2,2,2)
|
374
|
+
|
364
375
|
country '227', none >> split(4,4) # Niger http://www.wtng.info/wtng-227-ne.html
|
365
376
|
country '228', none >> split(4,4) # Togolese Republic http://www.wtng.info/wtng-228-tg.html
|
366
377
|
country '229', none >> split(4,4) # Benin http://www.itu.int/oth/T0202000017/en
|
367
378
|
|
368
|
-
|
379
|
+
# Mauritius
|
380
|
+
# http://www.wtng.info/wtng-230-mu.html
|
381
|
+
# https://en.wikipedia.org/wiki/Telephone_numbers_in_Mauritius
|
382
|
+
#
|
383
|
+
# There is no trunk code for this country.
|
384
|
+
country '230',
|
385
|
+
none >> matched_split(
|
386
|
+
/^5\d{7}$/ => [1,3,4], # Mobile
|
387
|
+
/^[246]\d{6}$/ => [3,4], # Landline
|
388
|
+
)
|
369
389
|
|
370
390
|
# Liberia
|
371
391
|
# https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=LR
|
@@ -474,7 +494,7 @@ Phony.define do
|
|
474
494
|
one_of('802') >> split(3,3) | # national rate
|
475
495
|
one_of(%w(251 252 271 272 281 282 293)) >> split(3,2) |
|
476
496
|
one_of(%w(21 23 24 26)) >> split(3,3) |
|
477
|
-
one_of(%w(82 84 86)) >> split(4,3) | # mobile
|
497
|
+
one_of(%w(82 83 84 85 86 87)) >> split(4,3) | # mobile
|
478
498
|
one_of('89') >> split(4,3) | # satellite GMPCS
|
479
499
|
one_of('7') >> split(4,4) | # universal access
|
480
500
|
one_of('9') >> split(4,4) | # premium rate
|
@@ -485,27 +505,32 @@ Phony.define do
|
|
485
505
|
# Zambia
|
486
506
|
# http://www.wtng.info/wtng-260-zm.html
|
487
507
|
# https://github.com/googlei18n/libphonenumber/
|
508
|
+
# https://en.wikipedia.org/wiki/Telephone_numbers_in_Zambia
|
509
|
+
|
488
510
|
country '260',
|
489
|
-
|
511
|
+
trunk('0') |
|
512
|
+
match(/^(75|76|77|94|95|96|97)/) >> split(3, 4) | # Mobile
|
490
513
|
match(/^(800)/) >> split(3,3) | # Toll free
|
491
514
|
match(/^(21[1-8])/) >> split(6) # Fixed
|
492
515
|
|
493
|
-
# Madagascar
|
516
|
+
# Madagascar
|
517
|
+
# https://en.wikipedia.org/wiki/Telephone_numbers_in_Madagascar
|
494
518
|
# http://www.itu.int/oth/T020200007F/en
|
495
519
|
country '261',
|
496
|
-
none >> matched_split(
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
)
|
520
|
+
# none >> matched_split(
|
521
|
+
# /\A20\d+\z/ => [2,2,3,2], # Telecom Malagasy (Telma)
|
522
|
+
# /\A32\d+\z/ => [2,2,3,2], # mobile Orange Madagascar
|
523
|
+
# /\A33\d+\z/ => [2,2,3,2], # mobile Airtel Madagascar
|
524
|
+
# /\A34\d+\z/ => [2,2,3,2], # mobile Telecom Malagasy (Telma)
|
525
|
+
# /\A38\d+\z/ => [2,2,3,2], # mobile Telecom Malagasy (Telma)
|
526
|
+
# /\A39\d+\z => [2,2,3,2] # mobile Blueline
|
527
|
+
# ),
|
528
|
+
match(/\A(20)\d+\z/) >> split(2,3,2) | # fix Telecom Malagasy (Telma)
|
529
|
+
match(/\A(32)\d+\z/) >> split(2,3,2) | # mobile Orange Madagascar
|
530
|
+
match(/\A(33)\d+\z/) >> split(2,3,2) | # mobile Airtel Madagascar
|
531
|
+
match(/\A(34)\d+\z/) >> split(2,3,2) | # mobile Telecom Malagasy (Telma)
|
532
|
+
match(/\A(38)\d+\z/) >> split(2,3,2) | # mobile Telecom Malagasy (Telma)
|
533
|
+
match(/\A(39)\d+\z/) >> split(2,3,2) # mobile Blueline Madagascar
|
509
534
|
|
510
535
|
country '262', # Reunion / Mayotte (new) http://www.wtng.info/wtng-262-fr.html
|
511
536
|
trunk('0') |
|
@@ -629,12 +654,12 @@ Phony.define do
|
|
629
654
|
match(/^(2[467]\d{2})\d{4}$/) >> split(2,2) | # 4-digit NDC
|
630
655
|
match(/^(6\d[18])\d+$/) >> split(3,3) | # mobile
|
631
656
|
match(/^(60\d{2})\d{8}$/) >> split(2,2,2,2) | # mobile machine to machine
|
632
|
-
match(/^((2[^467]|[
|
633
|
-
match(/^((2[^467]|[
|
634
|
-
match(/^((2[^467]|[
|
635
|
-
match(/^((2[^467]|[
|
636
|
-
match(/^((2[^467]|[
|
637
|
-
match(/^((2[^467]|[
|
657
|
+
match(/^((2[^467]|[2-9]\d))\d{4}$/) >> split(2,2) | # 2-digit NDC Regular 6 digits number
|
658
|
+
match(/^((2[^467]|[2-9]\d))\d{4}$/) >> split(2,2) | # 2-digit NDC Regular 6 digits number
|
659
|
+
match(/^((2[^467]|[2-9]\d))\d{5}$/) >> split(2,2,1) | # 2-digit NDC Regular 6 digits number w/ 1 digit extension
|
660
|
+
match(/^((2[^467]|[2-9]\d))\d{6}$/) >> split(2,2,2) | # 2-digit NDC Regular 8 digits number or 6 digits with 2 digits extension
|
661
|
+
match(/^((2[^467]|[2-9]\d))\d{7}$/) >> split(2,2,3) | # 2-digit NDC Regular 6 digits with 4 digits extension
|
662
|
+
match(/^((2[^467]|[2-9]\d))\d{8}$/) >> split(2,2,4) | # 2-digit NDC Regular 6 digits number with 4 digits extension
|
638
663
|
match(/^(\d{2})\d{3}$/) >> split(2,2,1) # fallback for 5 digit number
|
639
664
|
|
640
665
|
# country '353' # Republic of Ireland, see special file.
|
@@ -904,7 +929,14 @@ Phony.define do
|
|
904
929
|
)
|
905
930
|
|
906
931
|
country '671', todo # Spare code
|
907
|
-
|
932
|
+
|
933
|
+
# Australian External Territories https://en.wikipedia.org/wiki/Telephone_numbers_in_Norfolk_Island
|
934
|
+
# Norfolk Island
|
935
|
+
country '672',
|
936
|
+
fixed(1) >> split(2,3) |
|
937
|
+
match(/^(2\d+)$/) >> split(3) | # Fixed
|
938
|
+
match(/^(5\d+)$/) >> split(3) # Mobile
|
939
|
+
|
908
940
|
country '673', fixed(1) >> split(3, 3) # Brunei Darussalam http://www.wtng.info/wtng-673-bn.html
|
909
941
|
country '674', none >> split(3, 4) # Nauru (Republic of) http://www.wtng.info/wtng-674-nr.html
|
910
942
|
|
@@ -971,12 +1003,12 @@ Phony.define do
|
|
971
1003
|
/\A800\d+\z/ => [3,3], # freephone
|
972
1004
|
/\A830\d+\z/ => [3,3], # shared cost
|
973
1005
|
/\A60\d+\z/ => [3,3], # wireless geographic
|
974
|
-
/\A(72|75|76|77)\d+\z/ => [3,4], # mobile
|
1006
|
+
/\A(71|72|75|76|77)\d+\z/ => [3,4], # mobile
|
975
1007
|
/\A84\d+\z/ => [3,4], # wireless geographic
|
976
1008
|
/\A\d+\z/ => [2,3] # geographic
|
977
1009
|
)
|
978
1010
|
|
979
|
-
country '686', none >> split(
|
1011
|
+
country '686', none >> split(8) # Kiribati (Republic of) https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=KI
|
980
1012
|
country '687', none >> split(3,3) # New Caledonia (Territoire français d'outre-mer) http://www.wtng.info/wtng-687-nc.html
|
981
1013
|
country '688', none >> split(5) # Tuvalu http://www.wtng.info/wtng-688-tv.html
|
982
1014
|
country '689', none >> split(2,2,2,2) # French Polynesia (Territoire français d'outre-mer) http://www.wtng.info/wtng-689-pf.html
|
@@ -992,7 +1024,10 @@ Phony.define do
|
|
992
1024
|
country '698', todo # -
|
993
1025
|
country '699', todo # -
|
994
1026
|
|
995
|
-
|
1027
|
+
# International Freephone Service
|
1028
|
+
# https://www.itu.int/en/ITU-T/inr/unum/Pages/uifn.aspx
|
1029
|
+
country '800', none >> split(8)
|
1030
|
+
|
996
1031
|
country '801', todo # -
|
997
1032
|
country '802', todo # -
|
998
1033
|
country '803', todo # -
|
@@ -1000,7 +1035,7 @@ Phony.define do
|
|
1000
1035
|
country '805', todo # -
|
1001
1036
|
country '806', todo # -
|
1002
1037
|
country '807', todo # -
|
1003
|
-
country '808',
|
1038
|
+
country '808', none >> split(12) # International Shared Cost Service (ISCS)
|
1004
1039
|
country '809', todo # -
|
1005
1040
|
|
1006
1041
|
country '830', todo # -
|
@@ -1044,6 +1079,7 @@ Phony.define do
|
|
1044
1079
|
|
1045
1080
|
# Lao People's Democratic Republic http://www.wtng.info/wtng-856-la.html, https://www.numberingplans.com
|
1046
1081
|
country '856',
|
1082
|
+
trunk('0') |
|
1047
1083
|
one_of('30') >> split(3,4) | # geographic
|
1048
1084
|
one_of('20') >> split(4,4) | # mobile
|
1049
1085
|
fixed(2) >> split(3,3) # geographic
|
data/lib/phony/country.rb
CHANGED
@@ -97,6 +97,9 @@ module Phony
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
def format_cc_ndc trunk, ndc, local, type, space, parentheses, use_trunk
|
100
|
+
# Note: We mark NDCs that are of type "none" with false (nil trips plausible?). This would result in false being printed.
|
101
|
+
# Therefore we set NDC to nil when formatting.
|
102
|
+
ndc = nil if ndc == false
|
100
103
|
case type
|
101
104
|
when String
|
102
105
|
trunk &&= trunk.format(space, use_trunk)
|
@@ -125,6 +128,7 @@ module Phony
|
|
125
128
|
end
|
126
129
|
end
|
127
130
|
def format_ndc ndc, parentheses
|
131
|
+
ndc = nil if ndc == false # TODO
|
128
132
|
parentheses ? "(#{ndc})" : ndc
|
129
133
|
end
|
130
134
|
def format_with_ndc format, cc, ndc, local, space
|
data/lib/phony/country_codes.rb
CHANGED
@@ -97,9 +97,20 @@ module Phony
|
|
97
97
|
|
98
98
|
# False if it fails the basic check.
|
99
99
|
#
|
100
|
-
return false unless (4..16) === normalized.size
|
100
|
+
return false unless (4..16) === normalized.size # unless hints[:check_length] == false
|
101
101
|
|
102
102
|
country, cc, rest = partial_split normalized
|
103
|
+
|
104
|
+
# Was a country calling code given?
|
105
|
+
#
|
106
|
+
if ccc = hints[:ccc]
|
107
|
+
cc, ndc, *local = split ccc
|
108
|
+
|
109
|
+
raise ArgumentError.new("The provided ccc option is too long and includes more than a cc ('#{cc}') and ndc ('#{ndc}'). It also includes '#{local.join}'.") unless local.size == 1 && local[0].empty?
|
110
|
+
|
111
|
+
hints[:cc] = cc
|
112
|
+
hints[:ndc] = ndc
|
113
|
+
end
|
103
114
|
|
104
115
|
# Country code plausible?
|
105
116
|
#
|
@@ -109,6 +120,8 @@ module Phony
|
|
109
120
|
# Country specific tests.
|
110
121
|
#
|
111
122
|
country.plausible? rest, hints
|
123
|
+
rescue ArgumentError
|
124
|
+
raise
|
112
125
|
rescue StandardError
|
113
126
|
return false
|
114
127
|
end
|
@@ -31,9 +31,7 @@ module Phony
|
|
31
31
|
# since using nil is dangerous and breaks
|
32
32
|
# abstraction)
|
33
33
|
#
|
34
|
-
# Note:
|
35
|
-
#
|
36
|
-
# TODO Flip nil/false?
|
34
|
+
# Note: Decided it stays in. When formatting, it's turned into nil.
|
37
35
|
#
|
38
36
|
def split national_number
|
39
37
|
[nil, false, national_number]
|
@@ -18,27 +18,27 @@ describe 'Phony::Config' do
|
|
18
18
|
it 'does not fail when loading all' do
|
19
19
|
Phony::Config.load
|
20
20
|
|
21
|
-
Phony.split('15551115511').
|
21
|
+
expect(Phony.split('15551115511')).to eq ['1', '555', '111', '5511']
|
22
22
|
end
|
23
23
|
it 'raises when a CC is used that has not been loaded.' do
|
24
24
|
Phony::Config.load('41')
|
25
25
|
|
26
|
-
expect { Phony.split('15551115511') }.to raise_error
|
26
|
+
expect { Phony.split('15551115511') }.to raise_error(Phony::SplittingError)
|
27
27
|
end
|
28
28
|
it 'raises when a CC is used that has not been loaded.' do
|
29
29
|
Phony::Config.load(only: ['41'])
|
30
30
|
|
31
|
-
expect { Phony.split('15551115511') }.to raise_error
|
31
|
+
expect { Phony.split('15551115511') }.to raise_error(Phony::SplittingError)
|
32
32
|
end
|
33
33
|
it 'raises when a CC is used that has not been loaded.' do
|
34
34
|
Phony::Config.load(except: ['1'])
|
35
35
|
|
36
|
-
expect { Phony.split('15551115511') }.to raise_error
|
36
|
+
expect { Phony.split('15551115511') }.to raise_error(Phony::SplittingError)
|
37
37
|
end
|
38
38
|
it 'does not raise when a CC is used that has been loaded.' do
|
39
39
|
Phony::Config.load(except: ['41'])
|
40
40
|
|
41
|
-
Phony.split('15551115511').
|
41
|
+
expect(Phony.split('15551115511')).to eq ['1', '555', '111', '5511']
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|