phony 1.9.0 → 2.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/README.textile +1 -1
  2. data/lib/phony.rb +28 -15
  3. data/lib/phony/countries.rb +609 -210
  4. data/lib/phony/countries/austria.rb +6 -1
  5. data/lib/phony/countries/bangladesh.rb +55 -0
  6. data/lib/phony/countries/belarus.rb +130 -0
  7. data/lib/phony/countries/georgia.rb +91 -0
  8. data/lib/phony/countries/germany.rb +20 -6
  9. data/lib/phony/countries/india.rb +50 -0
  10. data/lib/phony/countries/indonesia.rb +50 -0
  11. data/lib/phony/countries/italy.rb +38 -67
  12. data/lib/phony/countries/japan.rb +412 -0
  13. data/lib/phony/countries/kyrgyzstan.rb +118 -0
  14. data/lib/phony/countries/latvia.rb +40 -0
  15. data/lib/phony/countries/libya.rb +114 -0
  16. data/lib/phony/countries/malaysia.rb +7 -5
  17. data/lib/phony/countries/moldova.rb +50 -0
  18. data/lib/phony/countries/montenegro.rb +27 -0
  19. data/lib/phony/countries/namibia.rb +35 -0
  20. data/lib/phony/countries/nepal.rb +71 -0
  21. data/lib/phony/countries/netherlands.rb +3 -2
  22. data/lib/phony/countries/pakistan.rb +119 -0
  23. data/lib/phony/countries/paraguay.rb +145 -0
  24. data/lib/phony/countries/russia_kazakhstan_abhasia_south_osetia.rb +6 -6
  25. data/lib/phony/countries/serbia.rb +34 -0
  26. data/lib/phony/countries/somali.rb +22 -0
  27. data/lib/phony/countries/south_korea.rb +1 -1
  28. data/lib/phony/countries/sweden.rb +1 -1
  29. data/lib/phony/countries/taiwan.rb +51 -0
  30. data/lib/phony/countries/tajikistan.rb +76 -0
  31. data/lib/phony/countries/turkmenistan.rb +73 -0
  32. data/lib/phony/countries/ukraine.rb +614 -0
  33. data/lib/phony/countries/uruguay.rb +51 -0
  34. data/lib/phony/countries/zimbabwe.rb +37 -0
  35. data/lib/phony/country.rb +41 -0
  36. data/lib/phony/country_codes.rb +45 -18
  37. data/lib/phony/dsl.rb +33 -7
  38. data/lib/phony/local_splitters/fixed.rb +14 -1
  39. data/lib/phony/local_splitters/regex.rb +12 -1
  40. data/lib/phony/national_code.rb +7 -3
  41. data/lib/phony/national_splitters/default.rb +13 -1
  42. data/lib/phony/national_splitters/dsl.rb +9 -7
  43. data/lib/phony/national_splitters/fixed.rb +6 -0
  44. data/lib/phony/national_splitters/none.rb +6 -0
  45. data/lib/phony/national_splitters/regex.rb +6 -0
  46. data/lib/phony/national_splitters/variable.rb +7 -1
  47. data/spec/lib/phony/countries_spec.rb +684 -16
  48. data/spec/lib/phony/local_splitters/regex_spec.rb +41 -0
  49. data/spec/lib/phony/validations_spec.rb +542 -10
  50. data/spec/lib/phony_spec.rb +20 -6
  51. metadata +29 -9
  52. data/lib/phony/validator.rb +0 -26
  53. data/lib/phony/validators.rb +0 -88
@@ -0,0 +1,145 @@
1
+ # Paraguay (Republic of)
2
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
3
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=PY
4
+
5
+ ndcs_with_6_7_subscriber_numbers = %w(
6
+ 21
7
+ 24
8
+ 25
9
+ 26
10
+ 28
11
+ 31
12
+ 32
13
+ 33
14
+ 36
15
+ 37
16
+ 38
17
+ 39
18
+ 41
19
+ 42
20
+ 43
21
+ 44
22
+ 46
23
+ 47
24
+ 48
25
+ 61
26
+ 71
27
+ 72
28
+ 73
29
+ 75
30
+ 81
31
+ 82
32
+ 83
33
+ 86
34
+ 91
35
+ 92
36
+ 93
37
+ 94
38
+ )
39
+
40
+ ndcs_with_6_subscriber_numbers = %w(
41
+ 271
42
+ 275
43
+ 291
44
+ 292
45
+ 293
46
+ 294
47
+ 295
48
+ 345
49
+ 351
50
+ 418
51
+ 451
52
+ 453
53
+ 464
54
+ 511
55
+ 512
56
+ 513
57
+ 514
58
+ 515
59
+ 516
60
+ 517
61
+ 518
62
+ 519
63
+ 520
64
+ 521
65
+ 522
66
+ 523
67
+ 524
68
+ 527
69
+ 528
70
+ 529
71
+ 531
72
+ 532
73
+ 533
74
+ 534
75
+ 535
76
+ 536
77
+ 537
78
+ 538
79
+ 539
80
+ 541
81
+ 542
82
+ 544
83
+ 545
84
+ 546
85
+ 547
86
+ 548
87
+ 549
88
+ 550
89
+ 552
90
+ 553
91
+ 554
92
+ 631
93
+ 632
94
+ 633
95
+ 644
96
+ 671
97
+ 672
98
+ 673
99
+ 674
100
+ 675
101
+ 676
102
+ 677
103
+ 678
104
+ 717
105
+ 718
106
+ 740
107
+ 741
108
+ 742
109
+ 743
110
+ 761
111
+ 762
112
+ 763
113
+ 764
114
+ 767
115
+ 768
116
+ 780
117
+ 781
118
+ 782
119
+ 783
120
+ 784
121
+ 785
122
+ 787
123
+ 858
124
+ 871
125
+ 873
126
+ 918
127
+ 951
128
+ 952
129
+ )
130
+
131
+ Phony.define do
132
+
133
+ country '595',
134
+ one_of(ndcs_with_6_subscriber_numbers) >> split(3,3) | # geographic
135
+ one_of(ndcs_with_6_7_subscriber_numbers) >>
136
+ matched_split(
137
+ /\A\d{6}\z/ => [3,3],
138
+ /\A\d+\z/ => [3,4]) | # geographic
139
+ one_of(%w(96 97 98 99)) >> split(3,4) | # mobile
140
+ fixed(2) >>
141
+ matched_split(
142
+ /\A\d{6}\z/ => [3,3],
143
+ /\A\d+\z/ => [3,4])
144
+
145
+ end
@@ -113,16 +113,16 @@ ndcs_with_6_subscriber_digits = %w(3012 3022 3412 3435 3439 3452 3456 3462 3463
113
113
  ndcs_with_7_subscriber_digits = %w(342 343 347 351 383 391 473 495 496 498 499 812 818 831 843 844 846 861 862 863)
114
114
 
115
115
  Phony.define do
116
- country '7', one_of(ndcs_with_5_subscriber_digits) >> split(1, 2, 2) |
117
- one_of(ndcs_with_6_subscriber_digits) >> split(2, 2, 2) |
118
- one_of(ndcs_with_7_subscriber_digits) >> split(3, 2, 2) |
119
- one_of(%w(800)) >> split(3, 2, 2) | # Russia free number
120
- one_of(%w(929 995344 9971 99744 9976 997)) >> split(2, 2, 2) | # South Osetia
116
+ country '7', one_of(ndcs_with_5_subscriber_digits) >> trunk('8') >> split(1, 2, 2) |
117
+ one_of(ndcs_with_6_subscriber_digits) >> trunk('8') >> split(2, 2, 2) |
118
+ one_of(ndcs_with_7_subscriber_digits) >> trunk('8') >> split(3, 2, 2) |
119
+ one_of(%w(800)) >> trunk('8') >> split(3, 2, 2) | # Russia free number
120
+ one_of(%w(929 995344 9971 99744 9976 997)) >> trunk('8') >> split(2, 2, 2) | # South Osetia
121
121
 
122
122
  # The two following lines have been replaced by fixed(3).
123
123
  #
124
124
  # match(/([67]\d{2})/) >> split(2, 2, 2) | # Kazakhstan: (600..799)
125
125
  # one_of(%w(840 940)) >> split(2,2,2) # Abhasia
126
126
 
127
- fixed(3) >> split(2,2,2)
127
+ fixed(3) >> trunk('8') >> split(2,2,3) # TODO 2,2,3 or 2,2,2?
128
128
  end
@@ -0,0 +1,34 @@
1
+ # Serbia
2
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=RS
3
+
4
+ Phony.define do
5
+ country '381',
6
+ one_of(%w(800)) >> split(3,2) | # freephone
7
+ one_of(%w(808)) >> split(3,2) | # payphone
8
+ one_of(%w(230)) >> matched_split(
9
+ /\A\d{4}\z/ => [4],
10
+ /\A\d+\z/ => [3,2]) |
11
+ one_of(%w(11 21)) >> matched_split(
12
+ /\A\d{6}\z/ => [3,3],
13
+ /\A\d+\z/ => [3,4]) |
14
+ one_of(%w(26 31 35)) >> split(3,3) |
15
+ one_of(%w(10 12 13 14 15 16 17 18 19 20 22 23 24 25 27 30 32 33 34 36 37)) >> matched_split(
16
+ /\A\d{5}\z/ => [3,2],
17
+ /\A\d+\z/ => [3,3]) |
18
+ one_of(%w(72)) >> split(3,3) | # ISP
19
+ one_of(%w(60 61 62 63 66 68 69)) >> matched_split(
20
+ /\A\d{3}\z/ => [3],
21
+ /\A\d{7}\z/ => [3,4],
22
+ /\A\d+\z/ => [3,3,4]) | # mobile, voicemail (mobile)
23
+ one_of(%w(64 65)) >> matched_split(
24
+ /\A\d{2}\z/ => [2],
25
+ /\A\d{3}\z/ => [3],
26
+ /\A\d{6}\z/ => [3,3],
27
+ /\A\d+\z/ => [3,3,4]) | # mobile, voicemail (mobile)
28
+ one_of(%w(70)) >> split(3,3) | # universal access
29
+ one_of(%w(42 78)) >> split(3,3) | # premium rate
30
+ one_of(%w(9)) >> split(3,4) | # premium rate
31
+ fixed(2) >> matched_split(
32
+ /\A\d{5}\z/ => [3,2],
33
+ /\A\d+\z/ => [3,3])
34
+ end
@@ -0,0 +1,22 @@
1
+ Phony.define do
2
+ # Somali Democratic Republic http://www.wtng.info/wtng-252-so.html
3
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=SO
4
+ country '252',
5
+ one_of('88216') >> split(3) | # Thuraya Satellite Telecommunications Company
6
+ one_of(%w(1034 1043)) >> split(3,2) | # Hortel
7
+ one_of(%w(1313)) >> split(3) | # Telcom Somalia
8
+ one_of(%w(160 161 162 163 164 165 166 167 168)) >> split(2,2) | # Hortel
9
+ one_of(%w(200 203 211 212 213 313)) >> split(3) | # Telcom Somalia
10
+ one_of(%w(201 204 208 210 214)) >> split(2,2) | # Telcom Somalia
11
+ one_of(%w(500 501 502 503 504 505 506 507 508 509)) >> split(3,2) | # mobile NationLink Telecom
12
+ one_of(%w(523 525 526)) >> split(2,2) | # Netco
13
+ one_of(%w(642 643 644 648 649)) >> split(2,2) | # Galcom
14
+ one_of(%w(33 51 52 54 55 56 57 58 59 68 71 76 78 79 88)) >> split(3,2) |
15
+ match(/\A(67)\d{5}\z/) >> split(3,2) | # Golis Telecom Somalia
16
+ one_of(%w(15 40 42 45 46 60 61 90 91)) >> split(3,3) | # mobile Somafone, Hortel
17
+ one_of(%w(18)) >> split(3,2) | # Hortel
18
+ one_of(%w(27 28 29 62 63 87)) >> split(2,2) | # Telcom Somalia, Emir Set
19
+ one_of(%w(67 69)) >> split(4,3) | # mobile NationLink Telecom
20
+ one_of('1') >> split(3,3) |
21
+ fixed(1) >> split(3,3)
22
+ end
@@ -12,7 +12,7 @@ special = %w{ 100 101 105 106 107 108 109 111 112 113 114 115 116 117 118 119 12
12
12
  Phony.define do
13
13
  country '82', match(/^(#{special.join("|")})$/) >> split(3,3) | # Special actually don't need to be split – but better err.
14
14
  one_of('2') >> split(4,4) | # Seoul, also includes "services".
15
- fixed(2) >> split(4,4) # catchall
15
+ fixed(2) >> split(4,4) # Catchall.
16
16
 
17
17
  # See above.
18
18
  #
@@ -8,7 +8,7 @@
8
8
  #
9
9
 
10
10
  ndcs = [
11
- '7', # Non-geographic
11
+ # '7', # Non-geographic - conflicts with mobile
12
12
  '8', # Stockholm
13
13
  '10', # VOIP
14
14
  '11', # Norrköping
@@ -0,0 +1,51 @@
1
+ # Taiwan
2
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
3
+ #
4
+
5
+ ndcs_with_8_subscriber_numbers = %w(1 2)
6
+
7
+ ndcs_with_7_subscriber_numbers = %w(3 4 5 6 7 8)
8
+
9
+ ndcs_with_6_subscriber_numbers = %w(
10
+ 33
11
+ 34
12
+ 35
13
+ 36
14
+ 37
15
+ 38
16
+ 39
17
+ 42
18
+ 43
19
+ 44
20
+ 45
21
+ 46
22
+ 47
23
+ 48
24
+ 49
25
+ 55
26
+ 56
27
+ 62
28
+ 66
29
+ 67
30
+ 69
31
+ 88
32
+ 89
33
+ )
34
+
35
+ ndcs_with_5_subscriber_numbers = %w(823 826 827)
36
+
37
+ Phony.define do
38
+ country '886',
39
+ one_of(ndcs_with_5_subscriber_numbers) >> split(3,2) |
40
+ match(/\A(6\d\d)\d{7}\z/) >> split(3,4) | # geographic ; Taipei
41
+ one_of(%w(412)) >> split(4) | # VoIP telephony ; Taichung
42
+ one_of(ndcs_with_6_subscriber_numbers) >> split(3,3) |
43
+ one_of(%w(18)) >> split(3,3) | # freephone
44
+ one_of(%w(90 91 92 93 95 96 97 98)) >> matched_split(
45
+ /\A\d{6}\z/ => [3,3],
46
+ /\A\d+\z/ => [3,4]) | # mobile
47
+ one_of(%w(60 70 94 95 99)) >> split(3,3) | # pager
48
+ one_of(ndcs_with_7_subscriber_numbers) >> split(3,4) |
49
+ one_of(ndcs_with_8_subscriber_numbers) >> split(4,4) |
50
+ fixed(2) >> split(3,3)
51
+ end
@@ -0,0 +1,76 @@
1
+ # Tajikistan (Republic of)
2
+
3
+ ndcs_with_6_subscriber_digits = %w(372)
4
+
5
+ ndcs_with_5_subscriber_digits = %w(
6
+ 3130
7
+ 3131
8
+ 3132
9
+ 3133
10
+ 3134
11
+ 3135
12
+ 3136
13
+ 3137
14
+ 3138
15
+ 3139
16
+ 3141
17
+ 3153
18
+ 3154
19
+ 3155
20
+ 3156
21
+ 3222
22
+ 3240
23
+ 3242
24
+ 3243
25
+ 3245
26
+ 3246
27
+ 3247
28
+ 3248
29
+ 3249
30
+ 3250
31
+ 3251
32
+ 3252
33
+ 3311
34
+ 3312
35
+ 3314
36
+ 3315
37
+ 3316
38
+ 3318
39
+ 3322
40
+ 3422
41
+ 3441
42
+ 3442
43
+ 3443
44
+ 3445
45
+ 3451
46
+ 3452
47
+ 3453
48
+ 3454
49
+ 3455
50
+ 3456
51
+ 3462
52
+ 3464
53
+ 3465
54
+ 3467
55
+ 3475
56
+ 3479
57
+ 3522
58
+ 3551
59
+ 3552
60
+ 3553
61
+ 3554
62
+ 3555
63
+ 3556
64
+ )
65
+
66
+ ndcs_with_3_subscriber_digits = %w(331700)
67
+
68
+ Phony.define do
69
+ country '992',
70
+ one_of(ndcs_with_3_subscriber_digits) >> trunk('8') >> split(3) |
71
+ one_of(ndcs_with_5_subscriber_digits) >> trunk('8') >> split(3,2) |
72
+ one_of(ndcs_with_6_subscriber_digits) >> trunk('8') >> split(3,3) |
73
+ match(/\A(505|9\d\d)\d+\z/) >> trunk('8') >> split(3,3) | # mobile
74
+ one_of(%w(446 474 487)) >> trunk('8') >> split(3,3) | # wireless geographic
75
+ fixed(3) >> trunk('8') >> split(3,3)
76
+ end
@@ -0,0 +1,73 @@
1
+ # Turkmenistan
2
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
3
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=TM
4
+
5
+ ndcs_with_6_subscriber_digits = %w(12)
6
+
7
+ ndcs_with_5_subscriber_digits = %w(
8
+ 131
9
+ 132
10
+ 133
11
+ 134
12
+ 135
13
+ 136
14
+ 137
15
+ 138
16
+ 222
17
+ 240
18
+ 241
19
+ 242
20
+ 243
21
+ 245
22
+ 246
23
+ 247
24
+ 248
25
+ 322
26
+ 340
27
+ 343
28
+ 344
29
+ 345
30
+ 346
31
+ 347
32
+ 348
33
+ 349
34
+ 360
35
+ 422
36
+ 431
37
+ 432
38
+ 438
39
+ 440
40
+ 441
41
+ 442
42
+ 443
43
+ 444
44
+ 445
45
+ 446
46
+ 447
47
+ 448
48
+ 449
49
+ 461
50
+ 465
51
+ 522
52
+ 557
53
+ 558
54
+ 559
55
+ 560
56
+ 561
57
+ 564
58
+ 565
59
+ 566
60
+ 568
61
+ 569
62
+ )
63
+
64
+ ndcs_with_4_subscriber_digits = %w(1392)
65
+
66
+ Phony.define do
67
+ country '993',
68
+ one_of(ndcs_with_4_subscriber_digits) >> trunk('8') >> split(4) |
69
+ one_of(ndcs_with_5_subscriber_digits) >> trunk('8') >> split(3,2) |
70
+ one_of(ndcs_with_6_subscriber_digits) >> trunk('8') >> split(3,3) |
71
+ one_of('6') >> trunk('8') >> split(3,4) | # mobile
72
+ fixed(3) >> trunk('8') >> split(3,2)
73
+ end