phony 1.9.0 → 2.19.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/README.textile +64 -112
  3. data/lib/phony/config.rb +91 -0
  4. data/lib/phony/countries/argentina.rb +355 -0
  5. data/lib/phony/countries/austria.rb +56 -22
  6. data/lib/phony/countries/bangladesh.rb +57 -0
  7. data/lib/phony/countries/belarus.rb +133 -0
  8. data/lib/phony/countries/brazil.rb +101 -95
  9. data/lib/phony/countries/cambodia.rb +131 -0
  10. data/lib/phony/countries/china.rb +13 -6
  11. data/lib/phony/countries/croatia.rb +23 -0
  12. data/lib/phony/countries/georgia.rb +94 -0
  13. data/lib/phony/countries/germany.rb +66 -42
  14. data/lib/phony/countries/guinea.rb +46 -0
  15. data/lib/phony/countries/india.rb +50 -0
  16. data/lib/phony/countries/indonesia.rb +55 -0
  17. data/lib/phony/countries/ireland.rb +35 -28
  18. data/lib/phony/countries/italy.rb +272 -166
  19. data/lib/phony/countries/japan.rb +468 -0
  20. data/lib/phony/countries/kyrgyzstan.rb +120 -0
  21. data/lib/phony/countries/latvia.rb +43 -0
  22. data/lib/phony/countries/libya.rb +116 -0
  23. data/lib/phony/countries/malaysia.rb +31 -7
  24. data/lib/phony/countries/moldova.rb +53 -0
  25. data/lib/phony/countries/montenegro.rb +30 -0
  26. data/lib/phony/countries/myanmar.rb +55 -0
  27. data/lib/phony/countries/namibia.rb +37 -0
  28. data/lib/phony/countries/nepal.rb +73 -0
  29. data/lib/phony/countries/netherlands.rb +17 -5
  30. data/lib/phony/countries/pakistan.rb +121 -0
  31. data/lib/phony/countries/paraguay.rb +147 -0
  32. data/lib/phony/countries/{russia_kazakhstan_abhasia_south_osetia.rb → russia_kazakhstan_abkhasia_south_ossetia.rb} +35 -24
  33. data/lib/phony/countries/saudi_arabia.rb +40 -0
  34. data/lib/phony/countries/serbia.rb +47 -0
  35. data/lib/phony/countries/somalia.rb +26 -0
  36. data/lib/phony/countries/south_korea.rb +19 -10
  37. data/lib/phony/countries/sweden.rb +58 -38
  38. data/lib/phony/countries/taiwan.rb +28 -0
  39. data/lib/phony/countries/tajikistan.rb +79 -0
  40. data/lib/phony/countries/turkmenistan.rb +76 -0
  41. data/lib/phony/countries/ukraine.rb +630 -0
  42. data/lib/phony/countries/united_kingdom.rb +639 -44
  43. data/lib/phony/countries/uruguay.rb +53 -0
  44. data/lib/phony/countries/vietnam.rb +133 -0
  45. data/lib/phony/countries/zimbabwe.rb +39 -0
  46. data/lib/phony/countries.rb +901 -301
  47. data/lib/phony/country.rb +177 -20
  48. data/lib/phony/country_codes.rb +119 -101
  49. data/lib/phony/dsl.rb +113 -68
  50. data/lib/phony/local_splitters/fixed.rb +25 -1
  51. data/lib/phony/local_splitters/regex.rb +16 -2
  52. data/lib/phony/national_code.rb +7 -7
  53. data/lib/phony/national_splitters/default.rb +35 -3
  54. data/lib/phony/national_splitters/dsl.rb +12 -7
  55. data/lib/phony/national_splitters/fixed.rb +7 -1
  56. data/lib/phony/national_splitters/none.rb +7 -3
  57. data/lib/phony/national_splitters/regex.rb +6 -0
  58. data/lib/phony/national_splitters/variable.rb +13 -9
  59. data/lib/phony/trunk_code.rb +57 -0
  60. data/lib/phony/vanity.rb +3 -3
  61. data/lib/phony.rb +239 -55
  62. data/spec/functional/config_spec.rb +44 -0
  63. data/spec/functional/plausibility_spec.rb +656 -0
  64. data/spec/lib/phony/countries_spec.rb +1207 -119
  65. data/spec/lib/phony/country_codes_spec.rb +99 -81
  66. data/spec/lib/phony/country_spec.rb +54 -14
  67. data/spec/lib/phony/dsl_spec.rb +2 -2
  68. data/spec/lib/phony/local_splitters/fixed_spec.rb +4 -4
  69. data/spec/lib/phony/local_splitters/regex_spec.rb +50 -2
  70. data/spec/lib/phony/national_code_spec.rb +34 -34
  71. data/spec/lib/phony/national_splitters/default_spec.rb +34 -0
  72. data/spec/lib/phony/national_splitters/fixed_spec.rb +12 -6
  73. data/spec/lib/phony/national_splitters/none_spec.rb +13 -3
  74. data/spec/lib/phony/national_splitters/regex_spec.rb +1 -1
  75. data/spec/lib/phony/national_splitters/variable_spec.rb +11 -5
  76. data/spec/lib/phony/trunk_code_spec.rb +85 -0
  77. data/spec/lib/phony/vanity_spec.rb +15 -19
  78. data/spec/lib/phony_spec.rb +59 -277
  79. metadata +67 -34
  80. data/lib/phony/validator.rb +0 -26
  81. data/lib/phony/validators.rb +0 -88
  82. data/spec/lib/phony/validations_spec.rb +0 -109
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Indian phone numbers.
4
+ #
5
+ # http://en.wikipedia.org/wiki/Telephone_numbers_in_India
6
+ # http://en.wikipedia.org/wiki/Mobile_telephone_numbering_in_India
7
+ #
8
+ # http://www.dot.gov.in/numbering_plan/numberplanindex.htm
9
+ # http://www.dot.gov.in/numbering_plan/nnp2003.pdf
10
+ # http://www.dot.gov.in/numbering_plan/2012/msc_codes_28092012.pdf
11
+ #
12
+ #
13
+
14
+
15
+ sdca_with_2_digits = %w{ 11 20 22 33 39 40 44 50 60 70 79 80 }
16
+
17
+ sdca_with_3_digits = %w{
18
+ 120 121 122 124 129 130 131 132 135 141 144 145 151 154 160 161 164 171 172 175 177 180 181 183 184 186 191 194
19
+ 210 212 217 230 231 233 239 240 241 249 250 251 254 257 260 261 265 268 270 272 278 281 285 286 288 291 294
20
+ 326 341 342 343 353 354 360 361 364 369 370 373 374 376 381 385 389
21
+ 413 416 421 423 424 427 431 435 451 452 461 462 469 470 471 474 475 476 477 478 479 480 481 483 484 485 487 490 491 494 495 496 497
22
+ 512 515 532 535 542 548 551 562 565 572 581 595
23
+ 612 621 631 641 651 657 661 663 671 674 680
24
+ 712 721 724 731 733 734 744 751 755 761 747 788
25
+ 816 820 821 824 831 832 836 861 863 866 870 877 878 883 884 891
26
+ 140
27
+ 240 249 254 260 270 272
28
+ 300 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 318 320 327 328 329 340 344 349 350 357 388
29
+ 412 419 430 438 439 450 453 458 459 460 464 466 467 468
30
+ 510 513 520 523 529 530 537 538 539 540 543 547 550 553 557 558 559 560 563 570 575 576 577 578 579 580 589 590 593 597 598 599
31
+ 610 614 616 617 619 620 623 626 628 629 630 635 636 637 638 639 640 644 648 649 650 660 669 670 677 687 688 689
32
+ 730 735 738 740 750 787 789
33
+ 812 814 829 843 860 879 880 887 889 890 895 897 898 899
34
+ }
35
+
36
+
37
+
38
+ mobile = %w{ 91 92 93 94 97 98 99 }
39
+
40
+ pagers = %w{ 96 }
41
+
42
+ Phony.define do
43
+ country '91',
44
+ trunk('0') |
45
+ one_of(sdca_with_3_digits) >> split(3, 2, 2) |
46
+ one_of(sdca_with_2_digits) >> split(3, 2, 3) |
47
+ one_of(mobile) >> split(3, 2, 3) |
48
+ one_of(pagers) >> split(2, 3, 3) |
49
+ fixed(4) >> split(3, 3) # fallback (4 digit sdca)
50
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Indonesia (Republic of)
4
+ # http://www.numberingplans.com/?page=dialling&sub=areacodes
5
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=ID
6
+
7
+ Phony.define do
8
+ country '62',
9
+ trunk('0') |
10
+ one_of('21') >> matched_split(
11
+ /\A\d{5}\z/ => [3,2],
12
+ /\A\d{7}\z/ => [3,4],
13
+ /\A\d+\z/ => [4,4]) |
14
+ one_of(%w(22 23 24 25 26 27 28 29 31 32 33 34 35 36 37 38 39 72)) >> matched_split(
15
+ /\A\d{5}\z/ => [3,2],
16
+ /\A\d{7}\z/ => [3,4],
17
+ /\A\d{8}\z/ => [4,4],
18
+ /\A\d{9}\z/ => [3,3,3]) |
19
+ one_of('70') >> split(3,3) |
20
+ one_of(%w(71 73 74 75 76 77)) >> matched_split(
21
+ /\A\d{6}\z/ => [3,3],
22
+ /\A\d+\z/ => [3,4]) |
23
+ one_of('13') >> matched_split( # pager
24
+ /\A\d{3}\z/ => [3],
25
+ /\A\d+\z/ => [3,3]) |
26
+ one_of(%w(174 175)) >> matched_split( # satellite
27
+ /\A\d{2}\z/ => [2],
28
+ /\A\d+\z/ => [2,3]) |
29
+ one_of('177') >> matched_split( # satellite
30
+ /\A\d{2}\z/ => [2],
31
+ /\A\d+\z/ => [4,4]) |
32
+ one_of('178') >> matched_split( # satellite
33
+ /\A\d{3}\z/ => [3],
34
+ /\A\d+\z/ => [3,2]) |
35
+ one_of(%w(870)) >> split(3,2) | # satellite
36
+ match(/\A(81\d|82\d|83\d|84\d|85\d|86\d|87\d|88\d|89\d)\d+\z/) >> matched_split( # mobile
37
+ /\A\d{6}\z/ => [3,3],
38
+ /\A\d{7}\z/ => [3,4],
39
+ /\A\d{8}\z/ => [4,4],
40
+ /\A\d+\z/ => [4,5]) |
41
+ one_of(%w(9)) >> matched_split( # geographic
42
+ /\A\d{7}\z/ => [4,3],
43
+ /\A\d+\z/ => [3,3,3]) |
44
+ one_of(%w(4 5)) >> matched_split(
45
+ /\A\d{6}\z/ => [3,3],
46
+ /\A\d+\z/ => [4,4]) |
47
+ one_of('6') >> matched_split(
48
+ /\A\d{7}\z/ => [3,4],
49
+ /\A\d+\z/ => [4,4]) |
50
+ one_of('9') >> matched_split(
51
+ /\A\d{7}\z/ => [3,4],
52
+ /\A\d+\z/ => [4,5]) |
53
+ fixed(2) >> split(4,4)
54
+ end
55
+
@@ -1,38 +1,38 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # The Republic of Ireland has variable-length NDCs from 2-3 digits in length. Depending on the NDC, the length of the subscriber number varies from 5-7 characters in length. There does not appear to be any pattern that relates NDCs to subscriber number length.
2
4
  #
3
5
  # 7 digit subscriber numbers follow a 3-4 split pattern.
4
- # 5 and 6 digit subscriber numbers appear split in some examples, and not in others; to be conservative, these are not currently split.
6
+ # 5 and 6 digit subscriber numbers appear split in some examples, and not in others; to be conservative, these are not currently split.
5
7
  #
6
- # For NDCs that are not recognized, we fall back to not attempting to split out an NDC at all.
8
+ # For NDCs that are not recognized, we fall back to not attempting to split out an NDC at all.
7
9
  #
8
10
  # References:
9
- # http://www.comreg.ie/_fileupload/publications/ComReg03147.pdf
11
+ # http://www.comreg.ie/_fileupload/publications/ComReg03147.pdf (2003)
12
+ # https://www.comreg.ie/media/dlm_uploads/2015/12/ComReg0804.pdf (2008)
13
+ # http://www.comreg.ie/licensing_and_services/area_code_maps.552.1040.html
10
14
  # http://en.wikipedia.org/wiki/Telephone_numbers_in_the_Republic_of_Ireland
11
15
  #
12
- handlers = []
13
-
14
16
  ndcs_with_5_subscriber_digits = [
15
- ('22'..'29').to_a, # Mallow, Bandon, Youghal, Fermoy, Macroom, Bantry, Skibbereen, Kanturk
16
- '402', # Arklow
17
- '404', # Wicklow
18
- '43', # Longford, Granard
19
- '44', # Mullingar, Castlepollard, Tyrellspass
20
- '47', # Monaghan, Clones
21
- '48', # Northern Ireland
22
- '502', # Portlaoise, Abbeyleix
23
- '504', # Thurles
24
- '505', # Roscrea
25
- '506', # Tullamore
26
- '509', # Bin-
27
- ('52'..'55').to_a, # Killenaule, Wexford, Enniscorthy, Ferns, Gorey
28
- '62', # Tipperary, Cashel
29
- '63', # Charleville
30
- '64', # Killarney, Rathmore
31
- '67', # Nenagh
32
- '68', # Listowel
33
- '69', # Newcastle West
34
- '93', # Tuam
35
- ('94'..'99').to_a # Castlebar, Castlerea, Claremorris, Clifden, Ballina, Belmullet, Westport, Kilronan
17
+ '22', '24', '25', '26', '27', '28', '29', # Mallow, Youghal, Fermoy, Macroom, Bantry, Skibbereen, Kanturk
18
+ '402', # Arklow
19
+ '404', # Wicklow
20
+ '47', # Monaghan, Clones
21
+ '48', # Northern Ireland
22
+ '502', # Portlaoise, Abbeyleix
23
+ '504', # Thurles
24
+ '505', # Roscrea
25
+ '506', # Tullamore
26
+ '509', # Bin-
27
+ '54', # Legacy Ferns, Enniscorthy
28
+ '55', # Legacy Gorey
29
+ '62', # Tipperary, Cashel
30
+ '63', # Charleville
31
+ '67', # Nenagh
32
+ '68', # Listowel
33
+ '69', # Newcastle West
34
+ '93', # Tuam
35
+ '94', '95', '96', '97', '98', '99' # Castlebar, Castlerea, Claremorris, Clifden, Ballina, Belmullet, Westport, Kilronan
36
36
  ].flatten
37
37
 
38
38
  ndcs_with_6_subscriber_digits = [
@@ -45,13 +45,19 @@ ndcs_with_6_subscriber_digits = [
45
45
  ndcs_with_7_subscriber_digits = [
46
46
  '1', # Dublin
47
47
  '21', # Cork, Coachford, Kinsale
48
+ '23', # Bandon
48
49
  '41', # Ardee
49
50
  '42', # Dundalk, Carrickmacross, Castleblaney
51
+ '43', # Longford, Granard
52
+ '44', # Mullingar, Castlepollard, Tyrellspass
50
53
  '46', # Navan, Kells, Trim, Enfield, Edenderry
51
54
  '49', # Cavan, Cootehill, Oldcastle, Belturbet
55
+ '52', # Killenaule
56
+ '53', # Wexford, Enniscorthy, Ferns, Gorey, Craanford
52
57
  '56', # Kilkenny, Castlecomer
53
58
  '58', # Dungarvan
54
59
  '59', # Carlow, Muine Bheag, Athy, Baltinglass
60
+ '64', # Killarney, Rathmore
55
61
  '65', # Ennistymon, Kilrush
56
62
  '66', # Tralee, Dingle, Killorglin, Cahirciveen
57
63
  '71', # Sligo, Manorhamilton, Carrick-on-Shannon
@@ -66,11 +72,12 @@ freefone = [
66
72
  ]
67
73
 
68
74
  Phony.define do
69
- country '353', one_of(ndcs_with_7_subscriber_digits) >> split(3,4) |
75
+ country '353', trunk('0') |
76
+ one_of(ndcs_with_7_subscriber_digits) >> split(3,4) |
70
77
  one_of(ndcs_with_5_subscriber_digits) >> split(5) |
71
78
  one_of(ndcs_with_6_subscriber_digits) >> split(6) |
72
79
  one_of(freefone) >> split(6) |
73
80
  match(/^(8\d).+$/) >> split(3,4) | # mobile
74
81
  fixed(3) >> split(6) # Fallback
75
82
 
76
- end
83
+ end
@@ -1,153 +1,266 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Italian phone numbers.
2
4
  #
3
5
  # http://en.wikipedia.org/wiki/Telephone_numbers_in_Italy
4
6
  #
5
7
 
6
8
  ndcs_2digit = [
7
- '02', # Milan
8
- '06', # Rome (including State of Vatican City) and Aprilia
9
+ '02', # Milan
10
+ '06', # Rome (including State of Vatican City) and Aprilia
11
+ ]
12
+
13
+ ndcs_3digit = [
14
+ '010', # Genoa
15
+ '011', # Turin
16
+ '015', # Biella
17
+ '019', # Savona
18
+ '030', # Brescia
19
+ '031', # Como
20
+ '035', # Bergamo
21
+ '039', # Monza
22
+ '040', # Trieste
23
+ '041', # Venice
24
+ '045', # Verona
25
+ '049', # Padua
26
+ '050', # Pisa
27
+ '051', # Bologna
28
+ '055', # Florence
29
+ '059', # Modena
30
+ '070', # Cagliari
31
+ '071', # Ancona
32
+ '075', # Perugia
33
+ '079', # Sassari
34
+ '080', # Bari
35
+ '081', # Naples
36
+ '085', # Pescara
37
+ '089', # Salerno
38
+ '090', # Messina
39
+ '091', # Palermo
40
+ '092', # Agrigento
41
+ '095', # Catania
42
+ '099', # Taranto
9
43
  ]
10
44
 
11
- ndcs = [
12
- '010', # Genoa
13
- '011', # Turin
14
- '0122', # Sestrieres, Bardonecchia and other Susa Valley mountain resorts
15
- '0125', # Ivrea
16
- '0131', # Alessandria
17
- '0141', # Asti
18
- '015', # Biella
19
- '0161', # Vercelli
20
- '0165', # Aosta, Courmayeur
21
- '0166', # Cervinia
22
- '0171', # Cuneo
23
- '0185', # Tigullio
24
- '0187', # La Spezia and Cinque Terre
25
- '019', # Savona
26
- '030', # Brescia
27
- '031', # Como
28
- '0321', # Novara
29
- '0331', # Varese
30
- '0341', # Lecco
31
- '0342', # Sondrio
32
- '035', # Bergamo
33
- '0369', # Mediaset Cologno Monzese and Segrate TV studios, geographical rate (used for polls, television programs, etc.)
34
- '0376', # Mantua
35
- '0382', # Pavia
36
- '039', # Monza
37
- '040', # Trieste
38
- '041', # Venice
39
- '0425', # Rovigo
40
- '0432', # Udine
41
- '0444', # Vicenza
42
- '045', # Verona
43
- '0461', # Trento
44
- '0471', # Bolzano
45
- '0481', # Gorizia
46
- '049', # Padua
47
- '050', # Pisa
48
- '051', # Bologna
49
- '0521', # Parma
50
- '0522', # Reggio nell'Emilia
51
- '0523', # Piacenza
52
- '0532', # Ferrara
53
- '0536', # Sassuolo
54
- '0541', # Rimini
55
- '0549', # San Marino (Most Serene Republic of San Marino)
56
- '055', # Florence
57
- '0573', # Pistoia
58
- '0577', # Siena
59
- '0586', # Livorno
60
- '059', # Modena
61
- '070', # Cagliari
62
- '071', # Ancona
63
- '075', # Perugia
64
- '0769', # RAI Saxa Rubra Studios, geographical rate (used for polls, television programs, etc.)
65
- '0771', # Fondi
66
- '0773', # Latina
67
- '0775', # Frosinone
68
- '0789', # Olbia and Costa Smeralda
69
- '079', # Sassari
70
- '080', # Bari
71
- '081', # Naples
72
- '0823', # Caserta
73
- '0824', # Benevento
74
- '0825', # Avellino
75
- '085', # Pescara
76
- '0865', # Isernia
77
- '0871', # Chieti
78
- '0872', # Lanciano
79
- '0873', # Vasto
80
- '0874', # Campobasso
81
- '0875', # Termoli
82
- '0881', # Foggia
83
- '089', # Salerno
84
- '090', # Messina
85
- '091', # Palermo
86
- '092', # Agrigento
87
- '095', # Catania
88
- '0961', # Catanzaro
89
- '0965', # Reggio di Calabria
90
- '0971', # Potenza
91
- '099', # Taranto
92
- ]
45
+ ndcs_4digit = [
46
+ '0121', # Pinerolo
47
+ '0122', # Sestrieres, Bardonecchia and other Susa Valley mountain resorts
48
+ '0123', # Lanzo Torinese
49
+ '0124', # Rivarolo Canavese
50
+ '0125', # Ivrea
51
+ '0131', # Alessandria
52
+ '0141', # Asti
53
+ '0142', # Casale Monferrato
54
+ '0143', # Novi Ligure
55
+ '0144', # Acqui Terme
56
+ '0161', # Vercelli
57
+ '0163', # Borgosesia
58
+ '0165', # Aosta, Courmayeur
59
+ '0166', # Cervinia
60
+ '0171', # Cuneo
61
+ '0172', # Savigliano
62
+ '0173', # Alba
63
+ '0174', # Mondoví
64
+ '0175', # Saluzzo
65
+ '0182', # Albenga
66
+ '0183', # Imperia
67
+ '0184', # San Remo
68
+ '0185', # Rapallo, Chiavari
69
+ '0187', # La Spezia and Cinque Terre
70
+ '0321', # Novara
71
+ '0322', # Arona
72
+ '0323', # Baveno
73
+ '0324', # Domodossola
74
+ '0331', # Busto Arsizio
75
+ '0332', # Varese
76
+ '0341', # Lecco
77
+ '0342', # Sondrio
78
+ '0343', # Chiavenna
79
+ '0344', # Menaggio
80
+ '0345', # San Pellegrino Terme
81
+ '0346', # Clusone
82
+ '0362', # Seregno
83
+ '0363', # Treviglio
84
+ '0364', # Breno
85
+ '0365', # Salò
86
+ '0369', # Mediaset Cologno Monzese and Segrate TV studios, premium rate (used for polls, television programs, etc.)
87
+ '0371', # Lodi
88
+ '0372', # Cremona
89
+ '0373', # Crema
90
+ '0374', # Soresina
91
+ '0375', # Casalmaggiore
92
+ '0376', # Mantua
93
+ '0377', # Codogno
94
+ '0381', # Vigevano
95
+ '0382', # Pavia
96
+ '0383', # Voghera
97
+ '0384', # Mortara
98
+ '0385', # Stradella
99
+ '0386', # Ostiglia
100
+ '0421', # San Donà di Piave
101
+ '0422', # Treviso
102
+ '0423', # Montebelluna
103
+ '0424', # Bassano del Grappa
104
+ '0425', # Rovigo
105
+ '0426', # Adria
106
+ '0427', # Spilimbergo
107
+ '0428', # Tarvisio
108
+ '0429', # Este
109
+ '0431', # Cervignano del Friuli
110
+ '0432', # Udine
111
+ '0433', # Tolmezzo
112
+ '0434', # Pordenone
113
+ '0435', # Pieve di Cadore
114
+ '0436', # Cortina d'Ampezzo
115
+ '0437', # Belluno
116
+ '0438', # Conegliano
117
+ '0439', # Feltre
118
+ '0442', # Legnano
119
+ '0444', # Vicenza
120
+ '0445', # Schio
121
+ '0461', # Trento
122
+ '0462', # Cavalese
123
+ '0463', # Cles
124
+ '0464', # Rovereto
125
+ '0465', # Tione di Trento
126
+ '0471', # Bolzano
127
+ '0472', # Brixen
128
+ '0473', # Merano
129
+ '0474', # Bruneck
130
+ '0481', # Gorizia
131
+ '0521', # Parma
132
+ '0522', # Reggio nell'Emilia
133
+ '0523', # Piacenza
134
+ '0524', # Fidenza
135
+ '0525', # Fornovo di Taro
136
+ '0532', # Ferrara
137
+ '0533', # Comacchio
138
+ '0534', # Porretta Terme
139
+ '0535', # Mirandola
140
+ '0536', # Sassuolo
141
+ '0541', # Rimini
142
+ '0542', # Imola
143
+ '0543', # Forlì
144
+ '0544', # Ravenna
145
+ '0545', # Lugo
146
+ '0546', # Faenza
147
+ '0547', # Cesena
148
+ '0549', # San Marino (Most Serene Republic of San Marino)
149
+ '0564', # Grosseto
150
+ '0565', # Piombino
151
+ '0566', # Follonica
152
+ '0571', # Empoli
153
+ '0572', # Montecatini Terme
154
+ '0573', # Pistoia
155
+ '0574', # Prato
156
+ '0575', # Arezzo
157
+ '0577', # Siena
158
+ '0578', # Chianciano Terme
159
+ '0583', # Lucca
160
+ '0584', # Viareggio
161
+ '0585', # Massa
162
+ '0586', # Livorno
163
+ '0587', # Pontedera
164
+ '0588', # Volterra
165
+ '0721', # Province of Pesaro and Urbino
166
+ '0722', # Province of Pesaro and Urbino
167
+ '0731', # Jesi
168
+ '0732', # Fabriano
169
+ '0733', # Macerata
170
+ '0734', # Fermo
171
+ '0735', # San Benedetto del Tronto
172
+ '0736', # Ascoli Piceno
173
+ '0737', # Camerino
174
+ '0742', # Foligno
175
+ '0743', # Spoleto
176
+ '0744', # Terni
177
+ '0746', # Rieti
178
+ '0761', # Viterbo
179
+ '0763', # Orvieto
180
+ '0765', # Poggio Mirteto
181
+ '0766', # Civitavecchia
182
+ '0769', # RAI Saxa Rubra Studios, premium rate (used for polls, television programs, etc.)
183
+ '0771', # Formia, Fondi
184
+ '0773', # Latina
185
+ '0774', # Tivoli
186
+ '0775', # Frosinone
187
+ '0776', # Cassino
188
+ '0781', # Iglesias
189
+ '0782', # Lanusei
190
+ '0783', # Oristano
191
+ '0784', # Nuoro
192
+ '0785', # Macomer
193
+ '0789', # Olbia and Costa Smeralda
194
+ '0823', # Caserta
195
+ '0824', # Benevento
196
+ '0825', # Avellino
197
+ '0827', # Sant'Angelo dei Lombardi
198
+ '0828', # Campagna
199
+ '0831', # Brindisi
200
+ '0832', # Lecce
201
+ '0833', # Gallipoli
202
+ '0835', # Matera
203
+ '0836', # Maglie
204
+ '0861', # Teramo
205
+ '0862', # L'Aquila
206
+ '0863', # Avezzano
207
+ '0864', # Sulmona
208
+ '0865', # Isernia
209
+ '0871', # Chieti
210
+ '0872', # Lanciano
211
+ '0873', # Vasto
212
+ '0874', # Campobasso
213
+ '0875', # Termoli
214
+ '0881', # Foggia
215
+ '0882', # San Severo
216
+ '0883', # Barletta-Andria-Trani
217
+ '0884', # Manfredonia
218
+ '0885', # Cerignola
219
+ '0921', # Cefalù
220
+ '0922', # Agrigento
221
+ '0923', # Trapani
222
+ '0924', # Alcamo
223
+ '0925', # Sciacca
224
+ '0931', # Siracusa
225
+ '0932', # Ragusa
226
+ '0933', # Caltagirone
227
+ '0934', # Caltanisetta
228
+ '0935', # Enna
229
+ '0941', # Patti
230
+ '0942', # Taormina
231
+ '0961', # Catanzaro
232
+ '0962', # Crotone
233
+ '0963', # Vibo Valentia
234
+ '0964', # Locri
235
+ '0965', # Reggio di Calabria
236
+ '0966', # Palmi
237
+ '0967', # Soverato
238
+ '0968', # Lamezia Terme
239
+ '0971', # Potenza
240
+ '0972', # Melfi
241
+ '0973', # Lagonegro
242
+ '0974', # Vallo della Lucania
243
+ '0975', # Sala Consilina
244
+ '0976', # Muro Lucano
245
+ '0981', # Castrovillari
246
+ '0982', # Paola
247
+ '0983', # Rossano
248
+ '0984', # Cosenza
249
+ '0985', # Scalea
250
+ ]
93
251
 
94
- mobile = [
95
- '310',
96
- '31100',
97
- '31101',
98
- '31102',
99
- '31103',
100
- '31104',
101
- '31105',
102
- '313',
103
- '319',
104
- ('3200'..'3209').to_a,
105
- '322',
106
- ('3230'..'3239').to_a,
107
- ('3270'..'3279').to_a,
108
- ('3280'..'3289').to_a,
109
- ('3290'..'3299').to_a,
110
- ('3300'..'3309').to_a,
111
- '331',
112
- ('3330'..'3339').to_a,
113
- ('3340'..'3349').to_a,
114
- ('3350'..'3359').to_a,
115
- ('3360'..'3369').to_a,
116
- ('3370'..'3379').to_a,
117
- ('3380'..'3389').to_a,
118
- ('3390'..'3399').to_a,
119
- ('3400'..'3409').to_a,
120
- '341',
121
- ('3430'..'3439').to_a,
122
- '345',
123
- ('3460'..'3469').to_a,
124
- ('3470'..'3479').to_a,
125
- ('3480'..'3489').to_a,
126
- ('3490'..'3499').to_a,
127
- '350',
128
- ('3600'..'3609').to_a,
129
- '361',
130
- '362',
131
- ('3630'..'3639').to_a,
132
- ('3660'..'3669').to_a,
133
- ('3680'..'3689').to_a,
134
- '370',
135
- '373',
136
- '377',
137
- ('3800'..'3809').to_a,
138
- ('3880'..'3889').to_a,
139
- ('3890'..'3899').to_a,
140
- ('3900'..'3909').to_a,
141
- ('3910'..'3919').to_a,
142
- ('3920'..'3929').to_a,
143
- ('3930'..'3939').to_a,
144
- '397'
145
- ].flatten
252
+ # All 3-- numbers are reserved for mobile phones according to
253
+ # http://en.wikipedia.org/wiki/Telephone_numbers_in_Italy#Mobile_telephones
254
+ # NOTE was:
255
+ # mobile = ('300'..'399').to_a
256
+ # but this was not frozen so easily.
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)
146
258
 
147
259
  service = [ # Not exhaustive.
148
260
  '112',
149
261
  '113',
150
262
  '115',
263
+ '116',
151
264
  '117',
152
265
  '118',
153
266
  '1515',
@@ -155,34 +268,27 @@ service = [ # Not exhaustive.
155
268
  '1530'
156
269
  ]
157
270
 
158
- # TODO Normalize!
159
- #
160
- # country '39', one_of(*service) >> split(3,3) |
161
- # one_of(*mobile) >> split(3,4) |
162
- # one_of(*ndcs, :max_length => 3) >> split(3,4)
163
-
164
- handlers = []
165
- handlers << Phony::NationalCode.new(
166
- Phony::NationalSplitters::Variable.new(nil, service),
167
- Phony::LocalSplitters::Fixed.instance_for([4, 4]),
168
- false
169
- )
170
- handlers << Phony::NationalCode.new(
171
- Phony::NationalSplitters::Variable.new(nil, mobile),
172
- Phony::LocalSplitters::Fixed.instance_for([3, 4]),
173
- false
174
- )
175
- handlers << Phony::NationalCode.new(
176
- Phony::NationalSplitters::Variable.new(nil, ndcs_2digit),
177
- Phony::LocalSplitters::Fixed.instance_for([4, 4]),
178
- false
179
- )
180
- handlers << Phony::NationalCode.new(
181
- Phony::NationalSplitters::Variable.new(3, ndcs),
182
- Phony::LocalSplitters::Fixed.instance_for([3, 4]),
183
- false
184
- )
185
-
186
271
  Phony.define do
187
- country '39', Phony::Country.new(*handlers)
188
- end
272
+ country '39', trunk('', normalize: false) |
273
+ one_of(*service) >> split(3,3) |
274
+ one_of(*mobile) >> split(3,4,-1..1) |
275
+ one_of(*ndcs_2digit) >> matched_split(
276
+ /\A\d{5}\z/ => [5],
277
+ /\A\d{6}\z/ => [4,2],
278
+ /\A\d{7}\z/ => [4,3],
279
+ /\A\d{8}\z/ => [4,4],
280
+ ) |
281
+ one_of(*ndcs_3digit) >> matched_split(
282
+ /^1\d{6}$/ => [7],
283
+ /^1\d{7}$/ => [8],
284
+ /^[^1]\d{5}$/ => [6],
285
+ /^[^1]\d{6}$/ => [7]
286
+ ) |
287
+ one_of(*ndcs_4digit) >> matched_split(
288
+ /\A\d{4}\z/ => [4],
289
+ /^1\d{5}$/ => [6],
290
+ /^1\d{6}$/ => [7],
291
+ /^[^1]\d{4}$/ => [5],
292
+ /^[^1]\d{5}$/ => [3,3]
293
+ )
294
+ end