phony 2.18.15 → 2.20.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d8b68b69c83acc6190f9fc36b4d9d3b0db6878ddc4bdb2c7cfabae8a77ee3ddc
4
- data.tar.gz: 1552ef3d9749adde09192d5951218ec399aac9bfe7d5a40c6c5ac50cac6003be
3
+ metadata.gz: 53e35e946aea7db6e2c7901a5df43de446fc04289fa976f4d2d655a09f4bdbae
4
+ data.tar.gz: f7f0cb0e4ee68d31a754d2c57fcde82116907fced053416c630eafcf71e8cd12
5
5
  SHA512:
6
- metadata.gz: 375e4422e3e19806732fb2ccfee87905754b56822538ae2eaf357d3e9fdc6d3d3cbdf800d10ea202c45f9c5bfc5cd3fd634f40964b5248fe6bd46c1632aef4c7
7
- data.tar.gz: 75f9f196bf936e481741a1c9f45f23bcc0d695843288505a57467d01edc8d0cdc1daa898083e12d402b582f0b8b46c22413d9b94e58714fe54bbed6cd352ab60
6
+ metadata.gz: 4e43b987e4313294e70a389da3441e364c8c0cd4930344c2beaadaef58cc60afdf3fc8f265e75923968f8dba565988237067375d41f9546f1dae1c9d258c6aa3
7
+ data.tar.gz: b3d7ba6dd615c1d36be9b284da5a578c1f8d11937230bf73185f172250c74d17ffb5a00fe2002f787731c2970587c3e19c1be012469227f28763563389c2da95
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, 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, 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
 
@@ -9,14 +9,14 @@
9
9
  #
10
10
  # References:
11
11
  # http://www.comreg.ie/_fileupload/publications/ComReg03147.pdf (2003)
12
+ # https://www.comreg.ie/media/dlm_uploads/2015/12/ComReg0804.pdf (2008)
12
13
  # http://www.comreg.ie/licensing_and_services/area_code_maps.552.1040.html
13
14
  # http://en.wikipedia.org/wiki/Telephone_numbers_in_the_Republic_of_Ireland
14
15
  #
15
16
  ndcs_with_5_subscriber_digits = [
16
- '22', '23', '24', '25', '26', '27', '28', '29', # Mallow, Bandon, Youghal, Fermoy, Macroom, Bantry, Skibbereen, Kanturk
17
+ '22', '24', '25', '26', '27', '28', '29', # Mallow, Youghal, Fermoy, Macroom, Bantry, Skibbereen, Kanturk
17
18
  '402', # Arklow
18
19
  '404', # Wicklow
19
- '43', # Longford, Granard
20
20
  '47', # Monaghan, Clones
21
21
  '48', # Northern Ireland
22
22
  '502', # Portlaoise, Abbeyleix
@@ -24,12 +24,10 @@ ndcs_with_5_subscriber_digits = [
24
24
  '505', # Roscrea
25
25
  '506', # Tullamore
26
26
  '509', # Bin-
27
- '52', # Killenaule
28
27
  '54', # Legacy Ferns, Enniscorthy
29
28
  '55', # Legacy Gorey
30
29
  '62', # Tipperary, Cashel
31
30
  '63', # Charleville
32
- '64', # Killarney, Rathmore
33
31
  '67', # Nenagh
34
32
  '68', # Listowel
35
33
  '69', # Newcastle West
@@ -47,15 +45,19 @@ ndcs_with_6_subscriber_digits = [
47
45
  ndcs_with_7_subscriber_digits = [
48
46
  '1', # Dublin
49
47
  '21', # Cork, Coachford, Kinsale
48
+ '23', # Bandon
50
49
  '41', # Ardee
51
50
  '42', # Dundalk, Carrickmacross, Castleblaney
51
+ '43', # Longford, Granard
52
52
  '44', # Mullingar, Castlepollard, Tyrellspass
53
53
  '46', # Navan, Kells, Trim, Enfield, Edenderry
54
54
  '49', # Cavan, Cootehill, Oldcastle, Belturbet
55
+ '52', # Killenaule
55
56
  '53', # Wexford, Enniscorthy, Ferns, Gorey, Craanford
56
57
  '56', # Kilkenny, Castlecomer
57
58
  '58', # Dungarvan
58
59
  '59', # Carlow, Muine Bheag, Athy, Baltinglass
60
+ '64', # Killarney, Rathmore
59
61
  '65', # Ennistymon, Kilrush
60
62
  '66', # Tralee, Dingle, Killorglin, Cahirciveen
61
63
  '71', # Sligo, Manorhamilton, Carrick-on-Shannon
@@ -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
- ndcs_2digit = [
8
+ ndcs_1digit = [
9
9
  '02', # Milan
10
10
  '06', # Rome (including State of Vatican City) and Aprilia
11
11
  ]
12
12
 
13
- ndcs_3digit = [
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
- ndcs_4digit = [
45
+ ndcs_3digit = [
46
46
  '0121', # Pinerolo
47
47
  '0122', # Sestrieres, Bardonecchia and other Susa Valley mountain resorts
48
48
  '0123', # Lanzo Torinese
@@ -269,20 +269,28 @@ service = [ # Not exhaustive.
269
269
  ]
270
270
 
271
271
  Phony.define do
272
- country '39', trunk('', :normalize => false) |
272
+ # Note: The 0 does not count towards NDC number length.
273
+ country '39', trunk('', normalize: false) |
273
274
  one_of(*service) >> split(3,3) |
274
275
  one_of(*mobile) >> split(3,4,-1..1) |
275
- one_of(*ndcs_2digit) >> split(4, 2..4) |
276
- one_of(*ndcs_3digit) >> matched_split(
277
- /^1\d{6}$/ => [7],
278
- /^1\d{7}$/ => [8],
279
- /^[^1]\d{5}$/ => [6],
280
- /^[^1]\d{6}$/ => [7]
276
+ one_of(*ndcs_1digit) >> matched_split(
277
+ /\A\d{5}\z/ => [5],
278
+ /\A\d{6}\z/ => [4,2],
279
+ /\A\d{7}\z/ => [4,3],
280
+ /\A\d{8}\z/ => [4,4],
281
281
  ) |
282
- one_of(*ndcs_4digit) >> matched_split(
283
- /^1\d{5}$/ => [6],
284
- /^1\d{6}$/ => [7],
285
- /^[^1]\d{4}$/ => [5],
286
- /^[^1]\d{5}$/ => [3,3]
282
+ one_of(*ndcs_2digit) >> matched_split(
283
+ /\A\d{4}\z/ => [4],
284
+ /\A\d{5}\z/ => [5],
285
+ /\A\d{6}\z/ => [6],
286
+ /\A\d{7}\z/ => [7],
287
+ /\A\d{8}\z/ => [8]
288
+ ) |
289
+ one_of(*ndcs_3digit) >> matched_split(
290
+ /\A\d{4}\z/ => [4],
291
+ /\A1\d{5}\z/ => [6],
292
+ /\A1\d{6}\z/ => [7],
293
+ /\A[^1]\d{4}\z/ => [5],
294
+ /\A[^1]\d{5}\z/ => [3,3]
287
295
  )
288
296
  end
@@ -166,6 +166,7 @@ ndcs_with_6_subscriber_numbers = %w(
166
166
  422
167
167
  428
168
168
  436
169
+ 438
169
170
  439
170
171
  460
171
172
  463
@@ -281,7 +282,6 @@ ndcs_with_6_subscriber_numbers = %w(
281
282
  846
282
283
  847
283
284
  848
284
- 849
285
285
  852
286
286
  853
287
287
  854
@@ -361,7 +361,6 @@ ndcs_with_5_subscriber_numbers = %w(
361
361
  1374
362
362
  1377
363
363
  1392
364
- 1394
365
364
  1397
366
365
  1398
367
366
  1456
@@ -393,7 +392,6 @@ ndcs_with_5_subscriber_numbers = %w(
393
392
  8477
394
393
  8512
395
394
  8514
396
- 8636
397
395
  9496
398
396
  9802
399
397
  9912
@@ -403,16 +401,68 @@ ndcs_with_5_subscriber_numbers = %w(
403
401
 
404
402
  Phony.define do
405
403
  country '81',
406
- trunk('0', :normalize => false, :format => true, :split => true) |
407
- one_of('20', '50', '60', '70', '90') >> split(4,4) | # mobile, VoIP telephony
404
+ trunk('0', normalize: true, format: true, split: true) |
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) |
408
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) |
409
456
  one_of(ndcs_with_6_subscriber_numbers) >> split(2,4) |
410
457
  one_of(%w(120)) >> split(3,3) | # freephone
411
- one_of(%w(120 800)) >> split(3,4) | # freephone
458
+ one_of(%w(800)) >> split(3,4) | # freephone
459
+ one_of(%w(180 570)) >> split(3,3) | # Tele-gong/Tele-dome, Navi-dial
460
+ one_of(%w(170 990)) >> split(2,4) | # Dengon-dial, Dial Q2 (discontinued)
461
+ one_of(%w(80)) >> split(4,4) | # mobile
412
462
  one_of(ndcs_with_7_subscriber_numbers) >> split(3,4) |
413
463
  one_of(ndcs_with_8_subscriber_numbers) >> split(4,4) |
414
464
  # TODO: 91(NDC) N(S)N length: 5-13 - Non-geographic number (Direct subscriber telephone service (legacy))
415
465
  fixed(2) >> split(4,4),
416
- :local_space => :- ,
417
- :space => :-
466
+ local_space: :-,
467
+ space: :-
418
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
@@ -8,6 +8,9 @@ Phony.define do
8
8
  trunk('0') |
9
9
  one_of(%w(800)) >> split(3,2) | # freephone
10
10
  one_of(%w(808)) >> split(3,2) | # payphone
11
+ one_of(%w(677 678)) >> matched_split(
12
+ /\A\d{4}\z/ => [3],
13
+ /\A\d+\z/ => [3,3]) |
11
14
  one_of(%w(230)) >> matched_split(
12
15
  /\A\d{4}\z/ => [4],
13
16
  /\A\d+\z/ => [3,2]) |
@@ -21,6 +24,7 @@ Phony.define do
21
24
  one_of(%w(72)) >> split(3,3) | # ISP
22
25
  one_of(%w(60 61 68 69)) >> matched_split(
23
26
  /\A\d{3}\z/ => [3],
27
+ /\A\d{6}\z/ => [3,3],
24
28
  /\A\d{7}\z/ => [3,4],
25
29
  /\A\d+\z/ => [3,3,4]) | # mobile, voicemail (mobile)
26
30
  one_of(%w(66 63)) >> matched_split(
@@ -40,4 +44,4 @@ Phony.define do
40
44
  fixed(2) >> matched_split(
41
45
  /\A\d{5}\z/ => [3,2],
42
46
  /\A\d+\z/ => [3,3])
43
- end
47
+ 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(
@@ -104,6 +104,7 @@ mobile = [
104
104
  '84', # Vinaphone
105
105
  '85', # Vinaphone
106
106
  '86', # Viettel
107
+ '87', # Itelecom
107
108
  '88', # Vinaphone
108
109
  '89', # MobiFone,
109
110
  '90', # MobiFone
@@ -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+$/) >> split(3,3) | # Premium and national rate Services
102
- match(/^(800|90\d)\d+$/) >> split(2,3) | # Toll free service and premium numbers
103
- match(/^(46[05678])\d{6}$/) >> split(2,2,2) | # Mobile (Lycamobile, Telenet, Join Experience, Proximus 0460)
104
- match(/^(4[789]\d)\d{6}$/) >> split(2,2,2) | # Mobile
105
- match(/^(45[56])\d{6}$/) >> split(2,2,2) | # Mobile Vikings and Voo
106
- one_of('2','3','4','9') >> split(3,2,2) | # Short NDCs
107
- fixed(2) >> split(2,2,2) # 2-digit NDCs
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)
@@ -352,13 +355,13 @@ Phony.define do
352
355
 
353
356
  # Côte d'Ivoire
354
357
  # http://www.wtng.info/wtng-225-ci.html
355
- # http://www.itu.int/dms_pub/itu-t/oth/02/02/T02020000310001PDFE.pdf
358
+ # https://www.itu.int/dms_pub/itu-t/oth/02/02/T02020000310006PDFE.pdf
356
359
  # http://en.wikipedia.org/wiki/Telephone_numbers_in_Ivory_Coast
357
360
  #
358
361
  # There is no trunk code for this country and several of the mobile prefixes start with 0
359
362
  country '225',
360
363
  trunk('', :normalize => false) |
361
- fixed(2) >> split(2,2,2)
364
+ fixed(2) >> split(2,2,2,2)
362
365
 
363
366
  country '226', none >> split(4,4) # Burkina Faso http://www.wtng.info/wtng-226-bf.html
364
367
  country '227', none >> split(4,4) # Niger http://www.wtng.info/wtng-227-ne.html
@@ -397,6 +400,7 @@ Phony.define do
397
400
  country '234',
398
401
  match(/^([7-9]0\d)\d+$/) >> split(3,4) | # Mobile
399
402
  match(/^(81\d)\d+$/) >> split(3,4) | # Mobile
403
+ match(/^(91\d)\d+$/) >> split(3,4) | # Mobile
400
404
  one_of('1', '2') >> split(3,3..4) | # Lagos, Ibadan
401
405
  one_of('9') >> split(3,4) | # Abuja
402
406
  one_of((30..79).map(&:to_s)) >> split(3,2..3) | # 2-digit NDC
@@ -409,7 +413,9 @@ Phony.define do
409
413
  country '239', fixed(1) >> split(3,3) # Sao Tome and Principe, http://www.wtng.info/wtng-239-st.html
410
414
 
411
415
  country '240', none >> split(3,3,3) # Equatorial Guinea
412
- country '241', fixed(1) >> split(3,3) # Gabonese Republic http://www.wtng.info/wtng-241-ga.html
416
+ country '241',
417
+ match(/^(\d)\d{6}$/) >> split(3,3) | # Gabonese Republic http://www.wtng.info/wtng-241-ga.html
418
+ match(/^(\d\d)\d{6}$/) >> split(2,2,2) # 2019 update https://en.wikipedia.org/wiki/Telephone_numbers_in_Gabon
413
419
  country '242', # Congo http://www.wtng.info/wtng-242-cg.html
414
420
  trunk('', :normalize => false) |
415
421
  none >> split(4,5)
@@ -429,9 +435,9 @@ Phony.define do
429
435
  # http://en.wikipedia.org/wiki/Telephone_numbers_in_Rwanda
430
436
  country '250',
431
437
  trunk('0') |
432
- one_of('25') >> split(7) | # Geographic, fixed
433
- match(/^(7[238])/) >> split(7) | # Non-geographic, mobile
434
- one_of('06') >> split(6) # Satellite
438
+ one_of('25') >> split(7) | # Geographic, fixed
439
+ match(/^(7[2389])/) >> split(7) | # Non-geographic, mobile
440
+ one_of('06') >> split(6) # Satellite
435
441
 
436
442
  country '251', fixed(2) >> split(3, 4) # Ethiopia http://www.wtng.info/wtng-251-et.html
437
443
 
@@ -482,27 +488,31 @@ Phony.define do
482
488
  # Zambia
483
489
  # http://www.wtng.info/wtng-260-zm.html
484
490
  # https://github.com/googlei18n/libphonenumber/
491
+ # https://en.wikipedia.org/wiki/Telephone_numbers_in_Zambia
485
492
  country '260',
486
- match(/^(9(5[034589]|[67]\d))/) >> split(6) | # Mobile
487
- match(/^(800)/) >> split(3,3) | # Toll free
488
- match(/^(21[1-8])/) >> split(6) # Fixed
493
+ trunk('0') |
494
+ match(/^(76|77|95|96|97)/) >> split(3, 4) | # Mobile
495
+ match(/^(800)/) >> split(3,3) | # Toll free
496
+ match(/^(21[1-8])/) >> split(6) # Fixed
489
497
 
490
- # Madagascar http://www.wtng.info/wtng-261-mg.html
498
+ # Madagascar
499
+ # https://en.wikipedia.org/wiki/Telephone_numbers_in_Madagascar
491
500
  # http://www.itu.int/oth/T020200007F/en
492
501
  country '261',
493
- none >> matched_split(
494
- /\A200\d+\z/ => [2,3,3,3], # Telecom Malagasy (Telma)
495
- /\A20\d+\z/ => [2,3,4], # Telecom Malagasy (Telma)
496
- /\A23\d+\z/ => [2,3,4], # Digitel
497
- /\A30\d+\z/ => [2,3,4], # mobile Madamobil (CDMA2000)
498
- /\A31\d+\z/ => [2,3,4], # mobile Airtel Madagascar
499
- /\A32\d+\z/ => [2,3,4], # mobile Orange Madagascar
500
- /\A33\d+\z/ => [2,3,4], # mobile Airtel Madagascar
501
- /\A34\d+\z/ => [2,3,4], # mobile Telecom Malagasy (Telma)
502
- /\A5\d+\z/ => [3,3,3], # pager
503
- /\A22\d+\z/ => [3,3,3], # satellite GULFSAT Téléphonie
504
- /\A6\d+\z/ => [3,3,3] # satellite
505
- )
502
+ # none >> matched_split(
503
+ # /\A20\d+\z/ => [2,2,3,2], # Telecom Malagasy (Telma)
504
+ # /\A32\d+\z/ => [2,2,3,2], # mobile Orange Madagascar
505
+ # /\A33\d+\z/ => [2,2,3,2], # mobile Airtel Madagascar
506
+ # /\A34\d+\z/ => [2,2,3,2], # mobile Telecom Malagasy (Telma)
507
+ # /\A38\d+\z/ => [2,2,3,2], # mobile Telecom Malagasy (Telma)
508
+ # /\A39\d+\z => [2,2,3,2] # mobile Blueline
509
+ # ),
510
+ match(/\A(20)\d+\z/) >> split(2,3,2) | # fix Telecom Malagasy (Telma)
511
+ match(/\A(32)\d+\z/) >> split(2,3,2) | # mobile Orange Madagascar
512
+ match(/\A(33)\d+\z/) >> split(2,3,2) | # mobile Airtel Madagascar
513
+ match(/\A(34)\d+\z/) >> split(2,3,2) | # mobile Telecom Malagasy (Telma)
514
+ match(/\A(38)\d+\z/) >> split(2,3,2) | # mobile Telecom Malagasy (Telma)
515
+ match(/\A(39)\d+\z/) >> split(2,3,2) # mobile Blueline Madagascar
506
516
 
507
517
  country '262', # Reunion / Mayotte (new) http://www.wtng.info/wtng-262-fr.html
508
518
  trunk('0') |
@@ -968,7 +978,7 @@ Phony.define do
968
978
  /\A800\d+\z/ => [3,3], # freephone
969
979
  /\A830\d+\z/ => [3,3], # shared cost
970
980
  /\A60\d+\z/ => [3,3], # wireless geographic
971
- /\A(72|75|76|77)\d+\z/ => [3,4], # mobile
981
+ /\A(71|72|75|76|77)\d+\z/ => [3,4], # mobile
972
982
  /\A84\d+\z/ => [3,4], # wireless geographic
973
983
  /\A\d+\z/ => [2,3] # geographic
974
984
  )
@@ -989,7 +999,10 @@ Phony.define do
989
999
  country '698', todo # -
990
1000
  country '699', todo # -
991
1001
 
992
- country '800', todo # International Freephone Service
1002
+ # International Freephone Service
1003
+ # https://www.itu.int/en/ITU-T/inr/unum/Pages/uifn.aspx
1004
+ country '800', none >> split(8)
1005
+
993
1006
  country '801', todo # -
994
1007
  country '802', todo # -
995
1008
  country '803', todo # -
@@ -997,7 +1010,7 @@ Phony.define do
997
1010
  country '805', todo # -
998
1011
  country '806', todo # -
999
1012
  country '807', todo # -
1000
- country '808', todo # International Shared Cost Service (ISCS)
1013
+ country '808', none >> split(12) # International Shared Cost Service (ISCS)
1001
1014
  country '809', todo # -
1002
1015
 
1003
1016
  country '830', todo # -
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
@@ -156,10 +160,12 @@ module Phony
156
160
  #
157
161
  # In some cases it doesn't, like Italy.
158
162
  #
159
- def normalize national_number
163
+ # Note: Options such as CC
164
+ #
165
+ def normalize national_number, options = {}
160
166
  clean! national_number
161
167
  normalized = @codes.reduce national_number do |number, code|
162
- result = code.normalize number
168
+ result = code.normalize number, options
163
169
  break result if result
164
170
  number
165
171
  end
@@ -66,7 +66,7 @@ module Phony
66
66
  country, cc, number = partial_split number
67
67
  country
68
68
  end
69
- number = country.normalize number
69
+ number = country.normalize number, cc: cc
70
70
  countrify! number, cc
71
71
  end
72
72
 
@@ -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
@@ -62,6 +62,8 @@ module Phony
62
62
  #
63
63
  #
64
64
  def plausible? rest, hints = {}
65
+ return true if hints[:check_length] == false
66
+
65
67
  @length === rest.inject(0) { |total, part| total + part.size }
66
68
  end
67
69
 
@@ -26,7 +26,7 @@ module Phony
26
26
  #
27
27
  # Note: Some cases, like Italy, don't remove the relative zero.
28
28
  #
29
- def normalize national_number
29
+ def normalize national_number, options = {}
30
30
  national_number.gsub(/\A0+/, EMPTY_STRING)
31
31
  end
32
32
 
@@ -31,9 +31,7 @@ module Phony
31
31
  # since using nil is dangerous and breaks
32
32
  # abstraction)
33
33
  #
34
- # Note: Actually, it might stay in.
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]
@@ -6,9 +6,9 @@ module Phony
6
6
  # * code: The trunk code, e.g. 0.
7
7
  #
8
8
  # Options:
9
- # * normalize: Remove the trunk code when normalizing (only use if number scheme is defined unambiguously).
10
- # * split: Remove the trunk code when splitting (only use if number scheme is defined unambiguously).
11
- # * format: Add the trunk code when formatting (passing `false` will not add it).
9
+ # * normalize: [true (default), false] Remove the trunk code when normalizing (only use if number scheme is defined unambiguously).
10
+ # * split: [true, false (default)] Remove the trunk code when splitting (only use if number scheme is defined unambiguously).
11
+ # * format: [true (default), false] Add the trunk code when formatting (passing `false` will not add it).
12
12
  #
13
13
  def initialize code, options = {}
14
14
  @code = code
@@ -35,8 +35,8 @@ module Phony
35
35
 
36
36
  # Normalize normalizes the given national number.
37
37
  #
38
- def normalize national_number
39
- national_number.gsub! @trunk_code_replacement, EMPTY_STRING if @normalize
38
+ def normalize national_number, options = {}
39
+ national_number.gsub! @trunk_code_replacement, EMPTY_STRING if @normalize && options[:cc]
40
40
  return national_number
41
41
  end
42
42