phony 1.9.0 → 2.0.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,40 @@
1
+ # Latvia
2
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=LV
3
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
4
+
5
+ ndcs_with_5_subscriber_numbers = %w(
6
+ 630
7
+ 631
8
+ 632
9
+ 633
10
+ 634
11
+ 636
12
+ 637
13
+ 638
14
+ 639
15
+ 640
16
+ 641
17
+ 642
18
+ 643
19
+ 644
20
+ 645
21
+ 646
22
+ 647
23
+ 648
24
+ 650
25
+ 651
26
+ 652
27
+ 653
28
+ 654
29
+ 656
30
+ 657
31
+ )
32
+
33
+ ndcs_with_6_subscriber_numbers = %w(67)
34
+
35
+ Phony.define do
36
+ country '371',
37
+ one_of(ndcs_with_5_subscriber_numbers) >> trunk('8') >> split(3,2) |
38
+ one_of(ndcs_with_6_subscriber_numbers) >> trunk('8') >> split(3,3) |
39
+ fixed(3) >> trunk('8') >> split(3,2)
40
+ end
@@ -0,0 +1,114 @@
1
+ # Lybia, https://www.numberingplans.com/?page=dialling&sub=areacodes
2
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=LY
3
+
4
+ ndcs_with_7_subscriber_numbers = %w(21)
5
+
6
+ ndcs_with_6_subscriber_numbers = %w(
7
+ 22
8
+ 23
9
+ 24
10
+ 25
11
+ 26
12
+ 31
13
+ 41
14
+ 47
15
+ 51
16
+ 54
17
+ 57
18
+ 61
19
+ 63
20
+ 67
21
+ 71
22
+ 73
23
+ 81
24
+ 82
25
+ 84
26
+ 87
27
+ )
28
+
29
+ ndcs_with_5_subscriber_numbers = %w(
30
+ 205
31
+ 206
32
+ 224
33
+ 252
34
+ 271
35
+ 272
36
+ 274
37
+ 275
38
+ 277
39
+ 279
40
+ 281
41
+ 282
42
+ 284
43
+ 322
44
+ 323
45
+ 325
46
+ 326
47
+ 421
48
+ 422
49
+ 423
50
+ 425
51
+ 427
52
+ 452
53
+ 453
54
+ 454
55
+ 481
56
+ 482
57
+ 484
58
+ 521
59
+ 522
60
+ 523
61
+ 524
62
+ 526
63
+ 529
64
+ 551
65
+ 553
66
+ 554
67
+ 555
68
+ 581
69
+ 582
70
+ 583
71
+ 584
72
+ 623
73
+ 624
74
+ 625
75
+ 626
76
+ 627
77
+ 628
78
+ 629
79
+ 652
80
+ 653
81
+ 654
82
+ 655
83
+ 657
84
+ 681
85
+ 682
86
+ 683
87
+ 684
88
+ 685
89
+ 721
90
+ 723
91
+ 724
92
+ 725
93
+ 726
94
+ 727
95
+ 729
96
+ 731
97
+ 732
98
+ 733
99
+ 734
100
+ 821
101
+ 851
102
+ 852
103
+ 854
104
+ 884
105
+ )
106
+
107
+ Phony.define do
108
+ country '218',
109
+ one_of(ndcs_with_5_subscriber_numbers) >> split(3,2) |
110
+ one_of(ndcs_with_6_subscriber_numbers) >> split(3,3) |
111
+ one_of(ndcs_with_7_subscriber_numbers) >> split(4,3) |
112
+ one_of(%w(91 92)) >> split(4,3) | # mobile
113
+ fixed(2) >> split(3,3)
114
+ end
@@ -12,11 +12,13 @@ ndcs = [
12
12
  '9', # Kelantan, Pahang (except Cameron Highlands & Genting Highlands) & Terengganu
13
13
  ]
14
14
  mobile = %w{ 10 11 12 13 14 153 154 156 158 16 17 18 19 }
15
- service = %w{ 100 101 102 103 104 108 112 991 994 995 999 }
15
+ service = %w{ 100 101 102 103 104 108 991 994 995 999 } # Emergeny and Service numbers, only 3 digits long
16
+ freephone = %w{ 300 700 800 }
16
17
 
17
18
  Phony.define do
18
- country '60', one_of(service) >> split(3,3) | # Service
19
- one_of(mobile) >> split(8) | # Mobile
20
- one_of(ndcs) >> split(8) | # 1-digit NDCs
21
- fixed(2) >> split(8) # 2-digit NDCs (Also, fallback)
19
+ country '60', one_of(freephone) >> split(2,4) | # Freephone, Tollfree, Forwarding
20
+ # one_of(service) >> none | # Service
21
+ one_of(mobile) >> split(3,4) | # Mobile
22
+ one_of(ndcs) >> split(8) | # 1-digit NDCs
23
+ fixed(2) >> split(8) # 2-digit NDCs (Also, fallback)
22
24
  end
@@ -0,0 +1,50 @@
1
+ # Moldova
2
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
3
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=MD
4
+
5
+ ndcs_with_6_subscriber_numbers = %w(22)
6
+ ndcs_with_5_subscriber_numbers = %w(
7
+ 230
8
+ 231
9
+ 235
10
+ 236
11
+ 237
12
+ 241
13
+ 242
14
+ 243
15
+ 244
16
+ 246
17
+ 247
18
+ 248
19
+ 249
20
+ 250
21
+ 251
22
+ 252
23
+ 254
24
+ 256
25
+ 258
26
+ 259
27
+ 262
28
+ 263
29
+ 264
30
+ 265
31
+ 268
32
+ 269
33
+ 271
34
+ 272
35
+ 273
36
+ 277
37
+ 291
38
+ 293
39
+ 294
40
+ 297
41
+ 298
42
+ 299
43
+ )
44
+
45
+ Phony.define do
46
+ country '373',
47
+ one_of(ndcs_with_5_subscriber_numbers) >> split(3,2) |
48
+ one_of(ndcs_with_6_subscriber_numbers) >> split(3,3) |
49
+ fixed(3) >> split(3,2)
50
+ end
@@ -0,0 +1,27 @@
1
+ # Montenegro
2
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
3
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=ME
4
+
5
+ Phony.define do
6
+ country '382',
7
+ one_of(%w(80)) >> split(3,3) | # freephone
8
+ one_of(%w(20 30 31 40 52)) >> matched_split(
9
+ /\A\d{5}\z/ => [3,2],
10
+ /\A\d+\z/ => [3,3]) |
11
+ one_of(%w(32 33 50 51)) >> split(3,3) |
12
+ one_of(%w(77)) >> split(3,3) | # national geographic
13
+ one_of(%w(78)) >> split(3,3) | # VoIP telephony
14
+ one_of(%w(88)) >> split(3,3) | # shared cost
15
+ one_of(%w(94 95)) >> split(3,3) | # premium rate
16
+ one_of(%w(63 67 69 70)) >> matched_split(
17
+ /\A\d{3}\z/ => [3],
18
+ /\A\d{6}\z/ => [3,3],
19
+ /\A\d+\z/ => [3,3,4]) | # mobile, voicemail (mobile
20
+ one_of(%w(68)) >> matched_split(
21
+ /\A\d{2}\z/ => [2],
22
+ /\A\d{6}\z/ => [3,3],
23
+ /\A\d+\z/ => [2,4,4]) | # voicemail (mobile)
24
+ fixed(2) >> matched_split(
25
+ /\A\d{5}\z/ => [3,2],
26
+ /\A\d+\z/ => [3,3])
27
+ end
@@ -0,0 +1,35 @@
1
+ # Namibia
2
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
3
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=NA
4
+
5
+ Phony.define do
6
+ country '264',
7
+ one_of(%w(632532)) >> split(4) |
8
+ one_of(%w(6342)) >> matched_split(
9
+ /\A\d{3}\z/ => [3],
10
+ /\A\d+\z/ => [3,3]) |
11
+ one_of(%w(6362 6638)) >> split(4) |
12
+ one_of(%w(6642)) >> matched_split(
13
+ /\A\d{4}\z/ => [4],
14
+ /\A\d+\z/ => [3,3]) |
15
+ one_of(%w(6751)) >> split(3,2) |
16
+ one_of(%w(628)) >> split(4) |
17
+ one_of(%w(658)) >> split(5) |
18
+ one_of(%w(668)) >> matched_split(
19
+ /\A\d{4}\z/ => [4],
20
+ /\A\d{5}\z/ => [3,2],
21
+ /\A\d+\z/ => [3,3]) |
22
+ one_of(%w(61 63 64 65 67)) >> matched_split(
23
+ /\A\d{6}\z/ => [3,3],
24
+ /\A\d+\z/ => [3,3,3]) |
25
+ one_of(%w(66)) >> matched_split(
26
+ /\A\d{4}\z/ => [4],
27
+ /\A\d+\z/ => [3,3]) |
28
+ one_of(%w(62)) >> split(3,3) |
29
+ one_of(%w(67)) >> matched_split(
30
+ /\A\d{6}\z/ => [3,3],
31
+ /\A\d{7}\z/ => [4,3],
32
+ /\A\d+\z/ => [3,3,3]) |
33
+ one_of(%w(60 81 82 83 85)) >> split(4,3) |
34
+ fixed(2) >> split(3,3)
35
+ end
@@ -0,0 +1,71 @@
1
+ # Nepal
2
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
3
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=NP
4
+
5
+ ndcs_with_7_subscriber_digits = %w(1)
6
+
7
+ ndcs_with_6_subscriber_digits = %w(
8
+ 10
9
+ 11
10
+ 21
11
+ 23
12
+ 24
13
+ 25
14
+ 26
15
+ 27
16
+ 29
17
+ 31
18
+ 33
19
+ 35
20
+ 36
21
+ 37
22
+ 38
23
+ 41
24
+ 44
25
+ 46
26
+ 47
27
+ 49
28
+ 51
29
+ 53
30
+ 55
31
+ 56
32
+ 57
33
+ 61
34
+ 63
35
+ 64
36
+ 66
37
+ 67
38
+ 68
39
+ 69
40
+ 71
41
+ 75
42
+ 76
43
+ 77
44
+ 78
45
+ 79
46
+ 81
47
+ 82
48
+ 83
49
+ 84
50
+ 86
51
+ 87
52
+ 89
53
+ 91
54
+ 92
55
+ 93
56
+ 94
57
+ 95
58
+ 96
59
+ 97
60
+ 99
61
+ )
62
+
63
+ Phony.define do
64
+ country '977',
65
+ one_of(ndcs_with_6_subscriber_digits) >> split(3,3) |
66
+ one_of(%w(98)) >> split(4,4) | # mobile
67
+ one_of(ndcs_with_7_subscriber_digits) >> split(3,4) |
68
+ fixed(2) >> split(3,3)
69
+ end
70
+
71
+
@@ -52,6 +52,7 @@ service = [
52
52
 
53
53
  Phony.define do
54
54
  country '31', one_of(service) >> split(3,3) |
55
- one_of(['6'] + ndcs) >> split(8) | # mobile + landline
56
- fixed(3) >> split(8) # 8 is for mobile numbers, other numbers will work as well (they use 7).
55
+ one_of('6') >> split(2,2,2,2) | # mobile
56
+ one_of(ndcs) >> split(3,4) | # landline (geographic region)
57
+ fixed(3) >> split(3,3) # 3 digit ndc
57
58
  end
@@ -0,0 +1,119 @@
1
+ # Pakistan (Islamic Republic of)
2
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=PK
3
+
4
+ ndcs_with_8_subscriber_numbers = %w(21 42 58)
5
+
6
+ ndcs_with_7_subscriber_numbers = %w(
7
+ 22
8
+ 25
9
+ 40
10
+ 41
11
+ 44
12
+ 46
13
+ 47
14
+ 48
15
+ 49
16
+ 51
17
+ 52
18
+ 53
19
+ 55
20
+ 56
21
+ 57
22
+ 61
23
+ 62
24
+ 63
25
+ 64
26
+ 65
27
+ 66
28
+ 67
29
+ 68
30
+ 71
31
+ 74
32
+ 81
33
+ 86
34
+ 91
35
+ )
36
+
37
+ ndcs_with_6_subscriber_numbers = %w(
38
+ 232
39
+ 233
40
+ 235
41
+ 238
42
+ 242
43
+ 243
44
+ 244
45
+ 297
46
+ 298
47
+ 453
48
+ 454
49
+ 457
50
+ 459
51
+ 542
52
+ 543
53
+ 544
54
+ 546
55
+ 547
56
+ 604
57
+ 606
58
+ 608
59
+ 722
60
+ 723
61
+ 726
62
+ 822
63
+ 823
64
+ 824
65
+ 825
66
+ 826
67
+ 828
68
+ 829
69
+ 832
70
+ 833
71
+ 835
72
+ 837
73
+ 838
74
+ 843
75
+ 844
76
+ 847
77
+ 848
78
+ 852
79
+ 853
80
+ 855
81
+ 856
82
+ 922
83
+ 923
84
+ 924
85
+ 925
86
+ 926
87
+ 927
88
+ 928
89
+ 932
90
+ 937
91
+ 938
92
+ 939
93
+ 942
94
+ 943
95
+ 944
96
+ 945
97
+ 946
98
+ 963
99
+ 965
100
+ 966
101
+ 969
102
+ 992
103
+ 995
104
+ 996
105
+ 997
106
+ 998
107
+ )
108
+
109
+ Phony.define do
110
+
111
+ country '92',
112
+ one_of(ndcs_with_6_subscriber_numbers) >> split(3,3) |
113
+ one_of('122') >> split(3,3) | # universal access
114
+ one_of(ndcs_with_7_subscriber_numbers) >> split(4,3) |
115
+ one_of(ndcs_with_8_subscriber_numbers) >> split(4,4) |
116
+ one_of(%w(30 31 32 33 34 35 36)) >> split(4,4) | # mobile
117
+ fixed(2) >> split(4,4)
118
+
119
+ end