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
@@ -1,20 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ndcs_with_5_subscriber_digits = %w(30130 30131 30132 30133 30134 30135 30136 30137 30138 30140 30141 30142 30143 30144
2
4
  30145 30146 30147 30148 30149 30150 30153 30230 30231 30232 30233 30234 30235 30236 30237 30238 30239 30240 30241
3
5
  30242 30243 30244 30245 30246 30247 30248 30249 30251 30252 30253 30255 30256 30257 30261 30262 30264 30265 30266
6
+ 33622
4
7
  34126 34130 34132 34133 34134 34136 34138 34139 34141 34145 34147 34150 34151 34152 34153 34154 34155 34157 34158
5
- 34159 34161 34162 34163 34164 34166 34240 34241 34242 34243 34244 34245 34246 34248 34249 34250 34251 34252 34253
8
+ 34159 34161 34162 34163 34164 34166 34240 34241 34243 34244 34245 34246 34248 34249 34250 34251 34252 34253
6
9
  34254 34255 34256 34257 34258 34259 34260 34261 34262 34263 34265 34266 34268 34269 34271 34272 34273 34274 34275
7
10
  34276 34277 34278 34279 34291 34292 34293 34294 34296 34297 34298 34341 34342 34343 34344 34345 34346 34347 34349
8
11
  34350 34355 34356 34357 34358 34360 34361 34362 34363 34364 34365 34367 34368 34369 34370 34371 34372 34373 34374
9
12
  34375 34376 34377 34380 34383 34384 34385 34386 34387 34388 34389 34391 34394 34395 34397 34398 34531 34533 34535
10
13
  34537 34539 34541 34542 34543 34544 34545 34546 34547 34550 34551 34553 34554 34555 34556 34557 34561 34634 34638
11
- 34643 34667 34668 34669 34670 34672 34673 34674 34675 34676 34677 34678 34731 34739 34740 34741 34742 34743 34744
14
+ 34643 34667 34668 34669 34670 34672 34674 34675 34676 34677 34678 34731 34739 34740 34741 34742 34743 34744
12
15
  34745 34746 34747 34748 34749 34750 34751 34752 34753 34754 34755 34756 34757 34758 34759 34760 34761 34762 34763
13
16
  34764 34765 34766 34767 34768 34769 34770 34771 34772 34773 34774 34775 34776 34777 34778 34779 34780 34781 34782
14
17
  34783 34784 34785 34786 34787 34788 34789 34791 34792 34794 34795 34796 34797 34798 34922 34932 34934 34936 34938
15
18
  34940 34948 34949 34992 34993 34994 34995 34996 34997 35130 35131 35133 35134 35138 35139 35140 35141 35142 35143
16
19
  35144 35145 35146 35147 35148 35149 35150 35151 35152 35153 35154 35155 35156 35157 35158 35159 35160 35161 35163
17
- 35164 35165 35166 35167 35168 35169 35190 35191 3522 35230 35231 35232 35233 35234 35235 35236 35237 35238 35239
20
+ 35164 35165 35166 35167 35168 35169 35190 35191 35230 35231 35232 35233 35234 35235 35236 35237 35238 35239
18
21
  35240 35241 35242 35243 35244 35245 35247 35248 35249 35251 35252 35253 35256 35257 35330 35331 35332 35333 35334
19
22
  35335 35336 35337 35338 35339 35341 35342 35344 35345 35346 35347 35348 35349 35351 35352 35354 35355 35356 35357
20
23
  35358 35359 35361 35362 35363 35364 35365 35366 35367 35368 35379 38141 38150 38151 38152 38153 38154 38155 38156
@@ -61,7 +64,9 @@ ndcs_with_5_subscriber_digits = %w(30130 30131 30132 30133 30134 30135 30136 301
61
64
  49146 49147 49148 49151 49152 49153 49154 49155 49156 49157 49158 49231 49232 49233 49234 49235 49236 49237 49238
62
65
  49241 49242 49243 49244 49245 49246 49247 49248 49254 49331 49333 49334 49336 49337 49339 49341 49343 49344 49345
63
66
  49346 49347 49349 49351 49352 49353 49354 49355 49356 49357 49430 49431 49432 49433 49434 49435 49436 49437 49438
64
- 49439 49440 49441 49442 49443 49444 49445 49446 49447 49448 49449 49450 49451 49452 49453 81131 81132 81133 81134
67
+ 49439 49440 49441 49442 49443 49444 49445 49446 49447 49448 49449 49450 49451 49452 49453 71036 71063 71133 71237
68
+ 71336 71337 71431 71433 71435 71536 71538 71543 71630 71636 71644 71645 71651 71837 72137 72153 72251 72335 72336
69
+ 72340 72433 72533 72537 72636 72752 72771 72772 72774 72775 72834 72835 81131 81132 81133 81134
65
70
  81135 81136 81137 81138 81139 81140 81141 81142 81143 81144 81145 81146 81147 81148 81149 81150 81151 81152 81153
66
71
  81361 81362 81363 81364 81365 81366 81367 81368 81369 81370 81371 81372 81373 81374 81375 81376 81378 81379 81430
67
72
  81431 81433 81434 81436 81437 81439 81450 81451 81452 81454 81455 81456 81457 81458 81459 81530 81531 81532 81533
@@ -85,7 +90,7 @@ ndcs_with_5_subscriber_digits = %w(30130 30131 30132 30133 30134 30135 30136 301
85
90
  84377 84378 84379 84396 84442 84443 84444 84445 84446 84447 84452 84453 84454 84455 84456 84457 84458 84461 84462
86
91
  84463 84464 84465 84466 84467 84468 84472 84473 84474 84475 84476 84477 84478 84479 84492 84493 84494 84495 84540
87
92
  84542 84543 84544 84545 84548 84549 84550 84551 84552 84554 84555 84557 84558 84560 84561 84562 84563 84564 84565
88
- 84566 84567 84568 84573 84574 84575 84576 84577 84578 84579 84591 84592 84593 84595 84596 84630 84635 84639 84646
93
+ 84566 84567 84568 84573 84574 84575 84576 84577 84578 84579 84591 84592 84593 84595 84596 84635 84639 84646
89
94
  84647 84648 84650 84651 84652 84653 84654 84655 84656 84657 84658 84660 84661 84663 84664 84666 84667 84670 84671
90
95
  84672 84673 84674 84675 84676 84677 84722 84731 84732 84733 84734 84735 84736 84741 84742 84743 84744 84745 84746
91
96
  84747 84862 85140 85141 85142 85143 85144 85145 85146 85147 85148 85149 85171 85172 85549 85551 85552 85555 85556
@@ -103,26 +108,32 @@ ndcs_with_5_subscriber_digits = %w(30130 30131 30132 30133 30134 30135 30136 301
103
108
  87872 87873 87874 87875 87876 87877 87878 87879 87922 87932 87934 87935 87937 87938 87951 87961 87964
104
109
  )
105
110
 
106
- ndcs_with_6_subscriber_digits = %w(3012 3022 3412 3435 3439 3452 3456 3462 3463 3466 3473 3494 3496 3513 3519 3532 3537
107
- 3812 3822 3823 3842 3843 3846 3852 3854 3882 3902 3919 3942 3952 3953 3955 4012 4112 4132 4152 4162 4212 4217 423 4234
108
- 4236 4242 4712 4722 4725 4742 4752 4812 4822 4832 4842 4852 4855 4862 4872 4912 4922 4932 4942 8112 8142 8152 8162
109
- 8172 8202 8212 8216 8313 8332 8342 8352 8362 8412 8422 8442 8443 8452 8453 8464 8482 8512 8552 8553 8555 8557 8617
110
- 862 8634 8635 8636 8639 8652 8662 8672 8712 8722 8732 8772 8782 8793
111
+ ndcs_with_6_subscriber_digits = %w(3012 3022 3412 3424 3435 3439 3452 3456 3462 3463 3466 3467 3473 3494 3496 3513 3519
112
+ 3522 3532 3537 3812 3822 3823 3842 3843 3846 3852 3854 3882 3902 3919 3942 3952 3953 3955 4012 4112 4132 4152 4162
113
+ 4212 4217 4234 4236 4242 4712 4722 4725 4742 4752 4812 4822 4832 4842 4852 4855 4862 4872 4912 4922 4932 4942
114
+ 7102 7112 7122 7132 7142 7152 7162 7172 7182 7187 7212 7213 7222 7232 7242 7252 7262 7272 7282 7292 8112 8142 8152
115
+ 8162 8172 8202 8212 8216 8313 8332 8342 8352 8362 8412 8422 8442 8443 8452 8453 8464 8482 8512 8552 8553 8555 8557
116
+ 8617 8622 8634 8635 8636 8639 8652 8662 8672 8712 8722 8732 8772 8782 8793
111
117
  )
112
118
 
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)
119
+ # 978, 869, and 365 are mobile, Sevastopol landlines, and Crimean landlines,
120
+ # which I can't wait to have removed from this library ASAP due to the illegal
121
+ # annexation of Ukrainian territory.
122
+ ndcs_with_7_subscriber_digits = %w(342 343 347 351 365 383 391 423 473 495 496 498 499 700 701 702 727 777 778 804 812
123
+ 818 831 843 844 846 861 863 869 900 901 902 903 904 905 906 908 909 910 911 912 913 914 915 916 917 918 919 920 921
124
+ 922 923 924 925 926 927 928 929 930 931 932 933 934 936 937 938 950 951 952 953 958 960 961 962 963 964 965 966 967
125
+ 968 969 977 978 980 981 982 983 984 985 986 987 988 989 992 993 995 996 997 999
126
+ )
114
127
 
115
128
  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
121
-
122
- # The two following lines have been replaced by fixed(3).
123
- #
124
- # match(/([67]\d{2})/) >> split(2, 2, 2) | # Kazakhstan: (600..799)
125
- # one_of(%w(840 940)) >> split(2,2,2) # Abhasia
126
-
127
- fixed(3) >> split(2,2,2)
128
- end
129
+ country '7',
130
+ # trunk('8', normalize: true, split: true) | # TODO Figure out if this is the way to go.
131
+ trunk('8', normalize: false) |
132
+ one_of(ndcs_with_5_subscriber_digits) >> split(1, 2, 2) |
133
+ one_of(ndcs_with_6_subscriber_digits) >> split(2, 2, 2) |
134
+ one_of(ndcs_with_7_subscriber_digits) >> split(3, 2, 2) |
135
+ one_of(%w(800)) >> split(3, 2, 2) | # Russia free number
136
+ one_of(%w(995344 9971 99744 9976 997)) >> split(2, 4) | # South Osetia
137
+ fixed(3) >> split(2, 5),
138
+ :local_space => :-
139
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ # References:
4
+ # http://www.itu.int/oth/T02020000B7/en
5
+ # https://en.wikipedia.org/wiki/Telephone_numbers_in_Saudi_Arabia
6
+
7
+ ndcs_with_7_subscriber_digits = [
8
+ '11', # Riyadh & the greater central region
9
+ '12', # Western region, includes Makkah, Jeddah, Taif, Rabigh
10
+ '13', # The Eastern Province, which includes, Dammam, Khobar, Qatif, Jubail, Dhahran, Hafar Al-Batin & others
11
+ '14', # Al-Madinah, Tabuk, Al-Jawf, Yanbu, Turaif, Skaka and Northern Borders Region
12
+ '16', # Al-Qassim, Buraidah, Majma & Hail
13
+ '17', # Southern regions like Asir, Al-Baha, Jizan, Najran & Khamis Mushait
14
+ '50', # Mobile: STC
15
+ '51', # Mobile: Trunking services
16
+ '52', # Mobile: Reserved for future use
17
+ '53', # Mobile: STC
18
+ '54', # Mobile: Mobily
19
+ '55', # Mobile: STC
20
+ '56', # Mobile: Mobily
21
+ '57', # Mobile
22
+ '58', # Mobile: Zain
23
+ '59', # Mobile: Zain
24
+ ]
25
+
26
+ toll_free = [
27
+ '800'
28
+ ]
29
+
30
+ universal_access = [
31
+ '9200'
32
+ ]
33
+
34
+ Phony.define do
35
+ country '966', trunk('0') |
36
+ one_of(ndcs_with_7_subscriber_digits) >> split(3,4) |
37
+ one_of(toll_free) >> split(3,4) |
38
+ one_of(universal_access) >> split(5) |
39
+ fixed(3) >> split(3,4)
40
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Serbia
4
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=RS
5
+
6
+ Phony.define do
7
+ country '381',
8
+ trunk('0') |
9
+ one_of(%w(800)) >> split(3,2) | # freephone
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]) |
14
+ one_of(%w(230)) >> matched_split(
15
+ /\A\d{4}\z/ => [4],
16
+ /\A\d+\z/ => [3,2]) |
17
+ one_of(%w(11 21)) >> matched_split(
18
+ /\A\d{6}\z/ => [3,3],
19
+ /\A\d+\z/ => [3,4]) |
20
+ one_of(%w(26 31 35)) >> split(3,3) |
21
+ 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(
22
+ /\A\d{5}\z/ => [3,2],
23
+ /\A\d+\z/ => [3,3]) |
24
+ one_of(%w(72)) >> split(3,3) | # ISP
25
+ one_of(%w(60 61 68 69)) >> matched_split(
26
+ /\A\d{3}\z/ => [3],
27
+ /\A\d{6}\z/ => [3,3],
28
+ /\A\d{7}\z/ => [3,4],
29
+ /\A\d+\z/ => [3,3,4]) | # mobile, voicemail (mobile)
30
+ one_of(%w(66 63)) >> matched_split(
31
+ /\A\d{3}\z/ => [3],
32
+ /\A\d{6}\z/ => [3,3],
33
+ /\A\d{7}\z/ => [3,4],
34
+ /\A\d+\z/ => [3,3,4]) | # mobile, voicemail (mobile)
35
+ one_of(%w(62 64 65)) >> matched_split(
36
+ /\A\d{2}\z/ => [2],
37
+ /\A\d{3}\z/ => [3],
38
+ /\A\d{6}\z/ => [3,3],
39
+ /\A\d{7}\z/ => [3,4],
40
+ /\A\d+\z/ => [3,3,4]) | # mobile, voicemail (mobile)
41
+ one_of(%w(70)) >> split(3,3) | # universal access
42
+ one_of(%w(42 78)) >> split(3,3) | # premium rate
43
+ one_of(%w(9)) >> split(3,4) | # premium rate
44
+ fixed(2) >> matched_split(
45
+ /\A\d{5}\z/ => [3,2],
46
+ /\A\d+\z/ => [3,3])
47
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ Phony.define do
4
+ # Somali Democratic Republic http://www.wtng.info/wtng-252-so.html
5
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=SO
6
+ # https://en.wikipedia.org/wiki/Telecommunications_in_Somaliland#Telesom
7
+ country '252',
8
+ one_of('88216') >> split(3) | # Thuraya Satellite Telecommunications Company
9
+ one_of(%w(1034 1043)) >> split(3,2) | # Hortel
10
+ one_of(%w(1313)) >> split(3) | # Telcom Somalia
11
+ one_of(%w(160 161 162 163 164 165 166 167 168)) >> split(2,2) | # Hortel
12
+ one_of(%w(200 203 211 212 213 313)) >> split(3) | # Telcom Somalia
13
+ one_of(%w(201 204 208 210 214)) >> split(2,2) | # Telcom Somalia
14
+ one_of(%w(500 501 502 503 504 505 506 507 508 509)) >> split(3,2) | # mobile NationLink Telecom
15
+ one_of(%w(523 525 526)) >> split(2,2) | # Netco
16
+ match(/\A(61|62|63|64|65|66|67|68|69|90)\d{7}\z/) >> split(3,4) | # mobile Hormuud, Somtel Mogadishu, Telesom, Hormuud, Somtel, Somtel Puntland, Nationlink Mogadishu, Nationlink Mogadishu, Nationlink, Golis
17
+ one_of(%w(642 643 644 648 649)) >> split(2,2) | # Galcom
18
+ one_of(%w(33 51 52 54 55 56 57 58 59 68 71 76 78 79 88)) >> split(3,2) |
19
+ match(/\A(67)\d{5}\z/) >> split(3,2) | # Golis Telecom Somalia
20
+ one_of(%w(15 40 42 45 46 60 61 90 91)) >> split(3,3) | # mobile Somafone, Hortel
21
+ one_of(%w(18)) >> split(3,2) | # Hortel
22
+ one_of(%w(27 28 29 62 63 87)) >> split(2,2) | # Telcom Somalia, Emir Set
23
+ one_of(%w(67 69)) >> split(4,3) | # mobile NationLink Telecom
24
+ one_of('1') >> split(3,3) |
25
+ fixed(1) >> split(3,3)
26
+ end
@@ -1,20 +1,29 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # South Korean (Republic of Korea) phone numbers.
2
4
  #
3
5
  # http://en.wikipedia.org/wiki/Telephone_numbers_in_South_Korea
6
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=KR
4
7
  #
5
8
 
6
9
  # TODO 4-digit services, like "unreasonable infringement of livelihood report" number :)
7
10
  #
8
11
 
9
- special = %w{ 100 101 105 106 107 108 109 111 112 113 114 115 116 117 118 119 120 121 122 123 125 127 128 129 131 132 134 141 182 188 }
10
- # mobile = ('10'..'19').to_a # Note: Mobile not used as it is (for now) handled by the fixed catchall.
12
+ special = %w(100 101 105 106 107 108 109 111 112 113 114 115 116 117 118 119 120 121 122 123 125 127 128 129 131 132 134 141 182 188)
13
+ # NOTE was:
14
+ # mobile = ('10'..'19').to_a
15
+ # but this was not frozen so easily.
16
+ mobile = %w(10 11 12 13 14 15 16 17 18 19)
11
17
 
12
18
  Phony.define do
13
- country '82', match(/^(#{special.join("|")})$/) >> split(3,3) | # Special actually don't need to be split – but better err.
14
- one_of('2') >> split(4,4) | # Seoul, also includes "services".
15
- fixed(2) >> split(4,4) # catchall
16
-
17
- # See above.
18
- #
19
- # one_of(*mobile) >> split(4,4) |
20
- end
19
+ country '82',
20
+ trunk('0') |
21
+ match(/^(#{special.join("|")})$/) >> split(3,3) | # Special actually don't need to be split – but better err.
22
+ one_of(*mobile) >> split(4,4) |
23
+ one_of('2') >> matched_split(
24
+ /\A\d{7}\z/ => [3,4],
25
+ /\A\d{8}\z/ => [4,4]) | # Seoul, also includes "services".
26
+ fixed(2) >> matched_split(
27
+ /\A\d{7}\z/ => [3,4],
28
+ /\A\d{8}\z/ => [4,4]) # Rest of cities
29
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Sweden uses a variable-length ndc code, thus we use a separate file to not let all_other.rb explode.
2
4
  #
3
5
  # Note: Sweden use a variable ndc format from length 2 to 3.
@@ -8,30 +10,31 @@
8
10
  #
9
11
 
10
12
  ndcs = [
11
- '7', # Non-geographic
12
- '8', # Stockholm
13
- '10', # VOIP
14
- '11', # Norrköping
15
- '13', # Linköping
16
- '16', # Eskilstuna-Torshälla
17
- '18', # Uppsala
18
- '19', # Örebro-Kumla
19
- '20', # toll-free
20
- '21', # Västerås
21
- '23', # Falun
22
- '26', # Gävle-Sandviken
23
- '31', # Göteborg
24
- '33', # Borås
25
- '35', # Halmstad
26
- '36', # Jönköping-Huskvarna
27
- '40', # Malmö
28
- '42', # Helsingborg-Höganäs
29
- '44', # Kristianstad
30
- '46', # Lund
31
- '54', # Karlstad
32
- '60', # Sundsvall-Timrå
33
- '63', # Östersund
34
- '90', # Umeå
13
+ # '7', # Non-geographic - conflicts with mobile
14
+ '8', # Stockholm
15
+ '10', # VOIP
16
+ '11', # Norrköping
17
+ '13', # Linköping
18
+ '16', # Eskilstuna-Torshälla
19
+ '18', # Uppsala
20
+ '19', # Örebro-Kumla
21
+ '20', # toll-free
22
+ '21', # Västerås
23
+ '23', # Falun
24
+ '26', # Gävle-Sandviken
25
+ '31', # Göteborg
26
+ '33', # Borås
27
+ '35', # Halmstad
28
+ '36', # Jönköping-Huskvarna
29
+ '40', # Malmö
30
+ '42', # Helsingborg-Höganäs
31
+ '44', # Kristianstad
32
+ '46', # Lund
33
+ '54', # Karlstad
34
+ '60', # Sundsvall-Timrå
35
+ '63', # Östersund
36
+ '90', # Umeå
37
+ '77', # Dalarna
35
38
  ]
36
39
  mobile = [
37
40
  '70', # Mobile
@@ -40,21 +43,38 @@ mobile = [
40
43
  '73', # Mobile
41
44
  '74', # Pagers
42
45
  '76', # Mobile
46
+ '79', # Mobile
47
+ ]
48
+ services = [
49
+ '112', # Emergency Service
50
+ '1177', # Health Care Advice
51
+ '11414', # Police
52
+ ]
53
+ service_ndcs = [
54
+ '99', # Premium Rate
55
+ '900', # Premium Rate
56
+ '939', # Premium Rate
57
+ '944', # Premium Rate
43
58
  ]
44
- service = [
45
- '99', # Premium Rate
46
- '112', # Emergency Service
47
- '116', # Psychological Help
48
- '118', # Number enquiries
49
- '900', # Premium Rate
50
- '939', # Premium Rate
51
- '944', # Premium Rate
52
- '1177', # Health Care Advice
53
- '11414', # Police
59
+ three_digit_service = [
60
+ '116', # Psychological Help (116 xxx)
61
+ '118', # Number enquiries (118 xxx)
54
62
  ]
55
63
 
56
64
  Phony.define do
57
- country '46', one_of(service) >> split(3,3) |
58
- one_of(ndcs + mobile) >> split(8) |
59
- fixed(3) >> split(8) # catchall
60
- end
65
+ country '46',
66
+ trunk('0') |
67
+ match(/^(#{services.join('|')})$/) >> split(0) |
68
+ one_of(service_ndcs) >> split(3,3) |
69
+ match(/^(#{three_digit_service.join('|')})\d{3}$/) >> split(3) |
70
+ one_of(ndcs + mobile) >> matched_split(
71
+ /^\d{5}$/ => [3, 2],
72
+ /^\d{6}$/ => [2, 2, 2],
73
+ /^\d{7}$/ => [3, 2, 2],
74
+ /^\d{8}$/ => [3, 2, 3]
75
+ ) |
76
+ fixed(3) >> matched_split(
77
+ /^\d{5}$/ => [3, 2],
78
+ /^\d{6}$/ => [2, 2, 2]
79
+ )
80
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Taiwan
4
+ # https://zh.wikipedia.org/wiki/%E4%B8%AD%E8%8F%AF%E6%B0%91%E5%9C%8B%E9%95%B7%E9%80%94%E9%9B%BB%E8%A9%B1%E5%8D%80%E8%99%9F%E8%A1%A8
5
+ # https://en.wikipedia.org/wiki/Telephone_numbers_in_Taiwan
6
+
7
+ Phony.define do
8
+ country '886',
9
+ trunk('0') |
10
+ match(/\A(826)\d{5}\z/) >> split(1,4) | # 烏坵, start with 0826, plus 5 digits
11
+ match(/\A(836)\d{5}\z/) >> split(1,4) | # 馬祖, start with 0836, plus 5 digits
12
+ match(/\A(82)\d{6}\z/) >> split(2,4) | # 金門, start with 082, plus 6 digits
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
15
+ match(/\A(8)\d{7}\z/) >> split(3,4) | # 屏東, start with 08, plus 7 digits
16
+ match(/\A(49)\d{7}\z/) >> split(3,4) | # 南投, start with 049, plus 7 digits
17
+ one_of(%w(4)) >> matched_split(
18
+ /\A\d{7}\z/ => [3,4], # 彰化, start with 04, plus 7 digits
19
+ /\A\d+\z/ => [4,4])| # 臺中, start with 04, plus 8 digits
20
+ match(/\A(37)\d{6}\z/) >> split(2,4) | # 苗栗, start with 037, plus 6 digits
21
+ match(/\A(3)\d{7}\z/) >> split(3,4) | # 桃園 新竹 花蓮 宜蘭, start with 03, plus 7 digits
22
+ match(/\A(5)\d{7}\z/) >> split(3,4) | # 嘉義 雲林, start with 05, plus 7 digits
23
+ match(/\A(6)\d{7}\z/) >> split(3,4) | # 臺南 澎湖, start with 06, plus 7 digits
24
+ match(/\A(7)\d{7}\z/) >> split(3,4) | # 高雄, start with 07, plus 7 digits
25
+ match(/\A(2)\d{8}\z/) >> split(4,4) | # 臺北, start with 02, plus 8 digits
26
+ match(/\A(9\d\d)\d{6}\z/) >> split(3,3) | # mobile phone, start with 09, plus 8 digits, but local usually show 4-3-3.
27
+ fixed(2) >> split(4,4) # fallback unknown
28
+ end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Tajikistan (Republic of)
4
+
5
+ ndcs_with_6_subscriber_digits = %w(372)
6
+
7
+ ndcs_with_5_subscriber_digits = %w(
8
+ 3130
9
+ 3131
10
+ 3132
11
+ 3133
12
+ 3134
13
+ 3135
14
+ 3136
15
+ 3137
16
+ 3138
17
+ 3139
18
+ 3141
19
+ 3153
20
+ 3154
21
+ 3155
22
+ 3156
23
+ 3222
24
+ 3240
25
+ 3242
26
+ 3243
27
+ 3245
28
+ 3246
29
+ 3247
30
+ 3248
31
+ 3249
32
+ 3250
33
+ 3251
34
+ 3252
35
+ 3311
36
+ 3312
37
+ 3314
38
+ 3315
39
+ 3316
40
+ 3318
41
+ 3322
42
+ 3422
43
+ 3441
44
+ 3442
45
+ 3443
46
+ 3445
47
+ 3451
48
+ 3452
49
+ 3453
50
+ 3454
51
+ 3455
52
+ 3456
53
+ 3462
54
+ 3464
55
+ 3465
56
+ 3467
57
+ 3475
58
+ 3479
59
+ 3522
60
+ 3551
61
+ 3552
62
+ 3553
63
+ 3554
64
+ 3555
65
+ 3556
66
+ )
67
+
68
+ ndcs_with_3_subscriber_digits = %w(331700)
69
+
70
+ Phony.define do
71
+ country '992',
72
+ trunk('8') |
73
+ one_of(ndcs_with_3_subscriber_digits) >> split(3) |
74
+ one_of(ndcs_with_5_subscriber_digits) >> split(3,2) |
75
+ one_of(ndcs_with_6_subscriber_digits) >> split(3,3) |
76
+ match(/\A(505|9\d\d)\d+\z/) >> split(3,3) | # mobile
77
+ one_of(%w(446 474 487)) >> split(3,3) | # wireless geographic
78
+ fixed(3) >> split(3,3)
79
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Turkmenistan
4
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
5
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=TM
6
+
7
+ ndcs_with_6_subscriber_digits = %w(12)
8
+
9
+ ndcs_with_5_subscriber_digits = %w(
10
+ 131
11
+ 132
12
+ 133
13
+ 134
14
+ 135
15
+ 136
16
+ 137
17
+ 138
18
+ 222
19
+ 240
20
+ 241
21
+ 242
22
+ 243
23
+ 245
24
+ 246
25
+ 247
26
+ 248
27
+ 322
28
+ 340
29
+ 343
30
+ 344
31
+ 345
32
+ 346
33
+ 347
34
+ 348
35
+ 349
36
+ 360
37
+ 422
38
+ 431
39
+ 432
40
+ 438
41
+ 440
42
+ 441
43
+ 442
44
+ 443
45
+ 444
46
+ 445
47
+ 446
48
+ 447
49
+ 448
50
+ 449
51
+ 461
52
+ 465
53
+ 522
54
+ 557
55
+ 558
56
+ 559
57
+ 560
58
+ 561
59
+ 564
60
+ 565
61
+ 566
62
+ 568
63
+ 569
64
+ )
65
+
66
+ ndcs_with_4_subscriber_digits = %w(1392)
67
+
68
+ Phony.define do
69
+ country '993',
70
+ trunk('8') |
71
+ one_of(ndcs_with_4_subscriber_digits) >> split(4) |
72
+ one_of(ndcs_with_5_subscriber_digits) >> split(3,2) |
73
+ one_of(ndcs_with_6_subscriber_digits) >> split(3,3) |
74
+ one_of('6') >> split(3,4) | # mobile
75
+ fixed(3) >> split(3,2)
76
+ end