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
data/README.textile CHANGED
@@ -13,7 +13,7 @@ This gem can normalize, format and split E164 numbers.
13
13
 
14
14
  The (admittedly crazy) *goal* of this Gem is to be able to format/split all phone numbers in the world.
15
15
 
16
- Currently handles Abhas, Afghan, Algerian, Austrian, Australian, Belgian, Brazilian, Cambodian, Chilean, Chinese, Croatian, Cuban, Cypriot, Czech, Danish, Dutch, Egyptian, Estonian, French, German, Ghanan, Gibraltar, Greek, Hungarian, Italian, Irish, Kazakh, Lithuanian, Luxembourgian, Malaysian, Malta, Mexican, Monaco, Morocco, New Zealand, Nigerian, Norwegian, Peruvian, Polish, Romanian, Russian, Rwandan, Singapore, Slovakian, South African, South Korean, South Osetian, Spanish, Sudan, Swedish, Swiss, Thailand, Tunisian, Turkish, Liechtenstein, UK, US, Venezuelan, and Vietnamese numbers.
16
+ Currently handles Abhas, Afghan, Algerian, Argentinan, 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, 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, and Vietnamese numbers.
17
17
 
18
18
  And to some extent, all others. Just try if it works for you.
19
19
 
data/lib/phony.rb CHANGED
@@ -12,8 +12,7 @@ require File.expand_path '../phony/national_splitters/none', __FILE__
12
12
  require File.expand_path '../phony/national_code', __FILE__
13
13
  require File.expand_path '../phony/country', __FILE__
14
14
  require File.expand_path '../phony/country_codes', __FILE__
15
- require File.expand_path '../phony/validator', __FILE__
16
- require File.expand_path '../phony/validators', __FILE__
15
+
17
16
  require File.expand_path '../phony/dsl', __FILE__
18
17
 
19
18
  # Countries.
@@ -21,28 +20,52 @@ require File.expand_path '../phony/dsl', __FILE__
21
20
  # The ones that need more space to define.
22
21
  #
23
22
  require File.expand_path '../phony/countries/austria', __FILE__
23
+ require File.expand_path '../phony/countries/bangladesh', __FILE__
24
+ require File.expand_path '../phony/countries/belarus', __FILE__
24
25
  require File.expand_path '../phony/countries/brazil', __FILE__
25
26
  require File.expand_path '../phony/countries/china', __FILE__
27
+ require File.expand_path '../phony/countries/georgia', __FILE__
26
28
  require File.expand_path '../phony/countries/germany', __FILE__
29
+ require File.expand_path '../phony/countries/india', __FILE__
30
+ require File.expand_path '../phony/countries/indonesia', __FILE__
27
31
  require File.expand_path '../phony/countries/ireland', __FILE__
28
32
  require File.expand_path '../phony/countries/italy', __FILE__
33
+ require File.expand_path '../phony/countries/japan', __FILE__
34
+ require File.expand_path '../phony/countries/kyrgyzstan', __FILE__
35
+ require File.expand_path '../phony/countries/latvia', __FILE__
36
+ require File.expand_path '../phony/countries/libya', __FILE__
29
37
  require File.expand_path '../phony/countries/malaysia', __FILE__
38
+ require File.expand_path '../phony/countries/moldova', __FILE__
39
+ require File.expand_path '../phony/countries/montenegro', __FILE__
40
+ require File.expand_path '../phony/countries/namibia', __FILE__
41
+ require File.expand_path '../phony/countries/nepal', __FILE__
30
42
  require File.expand_path '../phony/countries/netherlands', __FILE__
43
+ require File.expand_path '../phony/countries/pakistan', __FILE__
44
+ require File.expand_path '../phony/countries/paraguay', __FILE__
31
45
  require File.expand_path '../phony/countries/russia_kazakhstan_abhasia_south_osetia', __FILE__
46
+ require File.expand_path '../phony/countries/serbia', __FILE__
47
+ require File.expand_path '../phony/countries/somali', __FILE__
32
48
  require File.expand_path '../phony/countries/south_korea', __FILE__
33
49
  require File.expand_path '../phony/countries/sweden', __FILE__
50
+ require File.expand_path '../phony/countries/taiwan', __FILE__
51
+ require File.expand_path '../phony/countries/tajikistan', __FILE__
52
+ require File.expand_path '../phony/countries/turkmenistan', __FILE__
53
+ require File.expand_path '../phony/countries/ukraine', __FILE__
34
54
  require File.expand_path '../phony/countries/united_kingdom', __FILE__
55
+ require File.expand_path '../phony/countries/uruguay', __FILE__
56
+ require File.expand_path '../phony/countries/zimbabwe', __FILE__
35
57
  #
36
58
  # All other countries.
37
59
  #
38
60
  require File.expand_path '../phony/countries', __FILE__
39
61
 
62
+
63
+
40
64
  module Phony
41
65
 
42
66
  # Phony uses a single country codes instance.
43
67
  #
44
- @codes = CountryCodes.instance
45
- @validators = Validators.instance
68
+ @codes = CountryCodes.instance
46
69
 
47
70
  class << self
48
71
 
@@ -89,19 +112,9 @@ module Phony
89
112
  # leaning towards being plausible.
90
113
  #
91
114
  def plausible? number, hints = {}
92
- @validators.plausible? number, hints
115
+ @codes.plausible? number, hints
93
116
  end
94
117
 
95
- # def service? number
96
- # @codes.service? number.dup
97
- # end
98
- # def mobile? number
99
- # @codes.mobile? number.dup
100
- # end
101
- # def landline? number
102
- # @codes.landline? number.dup
103
- # end
104
-
105
118
  # Returns true if there is a character in the number
106
119
  # after the first four numbers.
107
120
  #
@@ -17,10 +17,6 @@
17
17
  # * matched_split: Give a hash of regex => format array, with a :fallback => format option.
18
18
  # (See Norway how it looks.)
19
19
  #
20
- # The third parameter to country are validations.
21
- # Currently, there is one method available:
22
- # * invalid_ndcs: Give a regexp or string to describe invalid ndc(s).
23
- #
24
20
  # Note: The ones that are commented are defined in their special files.
25
21
  #
26
22
  Phony.define do
@@ -32,10 +28,11 @@ Phony.define do
32
28
  # USA, Canada, etc.
33
29
  #
34
30
  country '1',
35
- fixed(3, :zero => false) >> split(3,4),
36
- invalid_ndcs('911') # /911/ would also work.
31
+ fixed(3, :zero => false) >> trunk('1') >> split(3,4),
32
+ # invalid_ndcs('911'), # /911/ would also work.
33
+ :invalid_ndcs => ['911'] # TODO
37
34
 
38
- # Kazakhstan (Republic of) & Russian Federation.
35
+ # Kazakhstan (Republic of) & Russsian Federation.
39
36
  # also Abhasia and South Osetia autonomous regions / recognized by some states as independent countries
40
37
  #country '7', fixed(3) >> split(3,2,2)
41
38
  # see special file
@@ -51,10 +48,19 @@ Phony.define do
51
48
  #
52
49
  country '27', fixed(2) >> split(3,4)
53
50
 
54
- # Greece.
55
- #
56
- country '30', match(/^(2[3-8]?1|69[0345789]|800)\d+$/) >> split(8) | # Geo/Mobile
57
- fixed(4) >> split(6) # 3-digit NDCs
51
+ # Greece. http://www.numberingplans.com/?page=dialling&sub=areacodes
52
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=GR
53
+ country '30',
54
+ one_of(%w(231 241 251 261 271 281)) >> split(3,4) |
55
+ one_of('800') >> split(3,4) | # freephone
56
+ one_of(%w(801 807)) >> split(3,4) | # shared cost, premium rate
57
+ one_of('896') >> split(3,4) | # ISP
58
+ one_of(%w(901 909)) >> split(3,4) | # premium rate
59
+ one_of(%w(21 22 23 24 25 26 27 28)) >> split(4,4) |
60
+ one_of('50') >> split(4,4) | # VPN
61
+ one_of('69') >> split(4,4) | # mobile, pager
62
+ one_of('70') >> split(4,4) | # universal access
63
+ fixed(4) >> split(6) # 3-digit NDCs
58
64
 
59
65
  # country '31' # Netherlands, see special file.
60
66
 
@@ -67,21 +73,19 @@ Phony.define do
67
73
 
68
74
  # France.
69
75
  #
70
- country '33', fixed(1) >> split(2,2,2,2) # :service? => /^8.*$/, :mobile? => /^[67].*$/
71
-
76
+ country '33', fixed(1) >> split(2,2,2,2) # :service? => /^8.*$/, :mobile? => /^[67].*$/
77
+
72
78
  # Spain.
73
79
  #
74
80
  country '34',
75
81
  fixed(2) >> split(3,4)
76
-
82
+
77
83
  # Hungary.
78
84
  #
79
- # TODO Mobile.
80
- #
81
85
  country '36',
82
- one_of('104','105','107','112') >> split(3,3) | # Service
83
- one_of('1') >> split(3,4) | # Budapest
84
- fixed(2) >> split(3,4) # 2-digit NDCs
86
+ one_of('104','105','107','112') >> trunk('06') >> split(3,3) | # Service
87
+ one_of('1') >> trunk('06') >> split(3,4) | # Budapest
88
+ fixed(2) >> trunk('06') >> split(3,4) # 2-digit NDCs
85
89
 
86
90
  # country '39' # Italy, see special file.
87
91
 
@@ -97,8 +101,7 @@ Phony.define do
97
101
  #
98
102
  country '41',
99
103
  match(/^(8(00|4[0248]))\d+$/) >> split(3,3) |
100
- fixed(2) >> split(3,2,2)
101
-
104
+ fixed(2) >> split(3,2,2)
102
105
 
103
106
  # country '43' # Austria, see special file.
104
107
  # country '44' # UnitedKingdom, see special file.
@@ -144,9 +147,9 @@ Phony.define do
144
147
  # Cuba.
145
148
  #
146
149
  country '53',
147
- match(/^(5\d{3})\d+$/) >> split(4) | # Mobile
150
+ match(/^(5\d{3})\d+$/) >> split(4) | # Mobile
148
151
  match(/^(7|2[123]|4[1-8]|3[1-3])/) >> split(7) | # Short NDCs
149
- fixed(3) >> split(7) # 3-digit NDCs
152
+ fixed(3) >> split(7) # 3-digit NDCs
150
153
 
151
154
  # Argentine Republic.
152
155
  #
@@ -155,6 +158,7 @@ Phony.define do
155
158
  match(/^(22[0137]|237|26[14]|29[179]|34[1235]|35[138]|38[1578])/) >> split(3,4) | # Fixed
156
159
  match(/^(922[0137]|9237|926[14]|929[179]|934[1235]|935[138]|938[1578])/) >> split(3,4) | # Mobile
157
160
  match(/^(9\d{4})/) >> split(2,4) | # Mobile
161
+ match(/^([68]\d{2})/) >> split(3,4) | # Service
158
162
  fixed(4) >> split(2,4) # Fixed
159
163
 
160
164
  # Brazil (Federative Republic of).
@@ -168,9 +172,11 @@ Phony.define do
168
172
  one_of('2', '9') >> split(8) | # Santiago, Mobile
169
173
  fixed(2) >> split(8) # 2-digit NDCs
170
174
 
171
- # TODO Colombia.
172
- #
173
- country '57', todo
175
+ # Colombia.
176
+ # http://www.itu.int/oth/T020200002C/en
177
+ country '57',
178
+ match(/\A(3\d\d)\d+\z/) >> split(3,4) | # mobile (300 310 311 312 313 315 316)
179
+ fixed(1) >> split(3,4)
174
180
 
175
181
  # Venezuela (Bolivarian Republic of)
176
182
  #
@@ -185,16 +191,19 @@ Phony.define do
185
191
  match(/^(4\d\d)\d+$/) >> split(3,3) | # Mobile
186
192
  fixed(1) >> split(4,4) # Rest
187
193
 
188
- # Indonesia (Republic of)
189
- country '62',
190
- one_of('21','22','24','31') >> split(7) |
191
- one_of('21','22','24','31') >> split(8) |
192
- fixed(3) >> split(5) |
193
- fixed(3) >> split(6) |
194
- fixed(3) >> split(7) |
195
- fixed(3) >> split(8)
194
+ # country '62' # Indonesia (Republic of), see special file
196
195
 
197
- country '63', todo # TODO Philippines (Republic of the)
196
+ # TODO Philippines (Republic of the)
197
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=PH
198
+ country '63',
199
+ # 7/10 digits for area code '2'.
200
+ match(/\A(2)\d{10}\z/) >> split(10) |
201
+ one_of('2') >> split(7) |
202
+ # mobile
203
+ match(/\A(9\d\d)\d{7}\z/) >> split(7) |
204
+ match(/\A(9\d\d)\d+\z/) >> split(6) |
205
+ #
206
+ fixed(2) >> split(7)
198
207
 
199
208
  # New Zealand.
200
209
  #
@@ -211,10 +220,11 @@ Phony.define do
211
220
  # Thailand.
212
221
  #
213
222
  country '66',
223
+ match(/\A(8\d\d)\d+\z/) >> split(3,3) | # mobile
214
224
  one_of('2') >> split(3,4) | # Bangkok
215
225
  fixed(2) >> split(3,3) # Rest
216
226
 
217
- country '81', todo # TODO Japan
227
+ # country '81' # Japan, see special file.
218
228
 
219
229
  # country '82' # SouthKorea, see special file.
220
230
 
@@ -222,53 +232,74 @@ Phony.define do
222
232
  one_of('4', '8') >> split(7) |
223
233
  match(/^(2[025679]|3[0136789]|5[23456789]|6[01234678]|7[02345679]|9[0-8])\d/) >> split(6) |
224
234
  fixed(3) >> split(5)
225
-
226
-
235
+
227
236
  # country '86' # China, see special file.
228
237
 
229
238
  # Turkey.
230
239
  #
231
240
  country '90',
232
- fixed(3) >> split(3,4) # Wiki says 7, but the examples say 3, 4.
241
+ fixed(3) >> split(3,4) # Wiki says 7, but the examples say 3, 4.
233
242
 
234
- country '91', todo # TODO India (Republic of)
235
- country '92', todo # TODO Pakistan (Islamic Republic of), http://en.wikipedia.org/wiki/Telephone_numbers_in_Pakistan, NDC 2-5
243
+ # country '91' # India (Republic of) see special file
244
+
245
+ # country '92' # Pakistan (Islamic Republic of), see special file.
236
246
 
237
247
  # Afghanistan.
238
248
  #
239
249
  # From http://www.wtng.info/wtng-93-af.html
240
250
  #
241
- country '93', fixed(2) >> split(7) # Note: the document says 6, but the examples use 7.
251
+ country '93', fixed(2) >> split(7) # Note: the document says 6, but the examples use 7.
252
+
253
+ country '94', # TODO Sri Lanka (Democratic Socialist Republic of)
254
+ fixed(2) >> split(3,2,2)
242
255
 
243
- country '94', fixed(2) >> split(3,2,2) # TODO Sri Lanka (Democratic Socialist Republic of)
244
256
  country '95', fixed(2) >> split(3,2,2) # TODO Myanmar (Union of)
245
- country '98', fixed(2) >> split(3,2,2) # TODO Iran (Islamic Republic of)
257
+
258
+ country '98', # Iran (Islamic Republic of)
259
+ one_of('21') >> split(4,4) | # Teheran
260
+ fixed(3) >> split(3,4)
246
261
 
247
262
  country '210', todo # -
248
- country '211', todo # South Sudan
249
- country '212', fixed(2) >> split(4,3) # Morocco
250
- country '213', fixed(2) >> split(3,4) # Algeria
263
+ country '211', fixed(3) >> split(3,3) # South Sudan, http://www.wtng.info/wtng-211-ss.html
264
+
265
+ country '212', # Morocco
266
+ one_of('6') >> split(2,2,2,2) | # mobile
267
+ fixed(2) >> split(4,3)
268
+
269
+ country '213', fixed(2) >> split(3,4) # Algeria
251
270
  country '214', todo # -
252
271
  country '215', todo # -
253
- country '216', fixed(1) >> split(3,4) # Tunisia
272
+ country '216', fixed(1) >> split(3,4) # Tunisia
254
273
  country '217', todo # -
255
- country '218', todo # Lybia
274
+
275
+ # country '218' # Lybia, see special file
276
+
256
277
  country '219', todo # -
257
278
 
258
- country '220', todo # Gambia
259
- country '221', todo # Senegal
260
- country '222', todo # Mauritania
261
- country '223', todo # Mali
262
- country '224', todo # Guinea
263
- country '225', todo # Côte d'Ivoire
264
- country '226', todo # Burkina Faso
265
- country '227', todo # Niger
266
- country '228', todo # Togolese Republic
267
- country '229', todo # Benin
268
-
269
- country '230', todo # Mauritius
270
- country '231', todo # Liberia
271
- country '232', todo # Sierra Leone
279
+ country '220', none >> split(3,4) # Gambia http://www.wtng.info/wtng-220-gm.html
280
+ country '221', none >> split(4,5) # Senegal http://www.wtng.info/wtng-221-sn.html
281
+ country '222', none >> split(4,4) # Mauritania http://www.wtng.info/wtng-222-mr.html
282
+ country '223', none >> split(4,4) # Mali http://www.wtng.info/wtng-223-ml.html
283
+ country '224', none >> split(4,4) # Guinea http://www.wtng.info/wtng-224-gn.html
284
+ country '225', none >> split(4,4) # Côte d'Ivoire http://www.wtng.info/wtng-225-ci.html
285
+ country '226', none >> split(4,4) # Burkina Faso http://www.wtng.info/wtng-226-bf.html
286
+ country '227', none >> split(4,4) # Niger http://www.wtng.info/wtng-227-ne.html
287
+ country '228', none >> split(4,4) # Togolese Republic http://www.wtng.info/wtng-228-tg.html
288
+ country '229', none >> split(4,4) # Benin http://www.itu.int/oth/T0202000017/en
289
+
290
+ country '230', none >> split(3,4) # Mauritius http://www.wtng.info/wtng-230-mu.html
291
+
292
+ # Liberia
293
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=LR
294
+ country '231',
295
+ none >> matched_split(
296
+ /\A[23]\d+\z/ => [4,4], # LIBTELCO, TEMAS
297
+ /\A[4568]\d+\z/ => [4,3], # mobile Lonestar, Libercell, Comium Liberia Inc.
298
+ /\A7\d+\z/ => [4,4], # mobile Cellcom
299
+ /\A9\d+\z/ => [4,4], # premium rate Telelinks International SAL, Interactive Media Corporation
300
+ )
301
+
302
+ country '232', fixed(2) >> split(3, 3) # Sierra Leone http://www.wtng.info/wtng-232-sl.html
272
303
 
273
304
  # Ghana
274
305
  #
@@ -279,40 +310,45 @@ Phony.define do
279
310
  # Nigeria
280
311
  # Wikipedia says 3 4 split, many local number with no splitting
281
312
  country '234',
282
- one_of('1', '2', '9') >> split(3,4) | # Lagos, Ibadan and Abuja
283
- match(/^(702\d)\d+$/) >> split(3,4) | # Mobile
284
- match(/^(70[3-9])\d+$/) >> split(3,4) | # Mobile
285
- match(/^(8[01]\d)\d+$/) >> split(3,4) | # Mobile
286
- fixed(2) >> split(3,4) # 2-digit NDC
287
-
288
-
289
- country '235', todo # Chad
290
- country '236', todo # Central African Republic
291
- country '237', todo # Cameroon
292
- country '238', todo # Cape Verde
293
- country '239', todo # Sao Tome and Principe
294
-
295
- country '240', todo # Equatorial Guinea
296
- country '241', todo # Gabonese Republic
297
- country '242', todo # Congo
298
- country '243', todo # Democratic Republic of the Congo
299
- country '244', todo # Angola
300
- country '245', todo # Guinea-Bissau
301
- country '246', todo # Diego Garcia
313
+ one_of('1', '2', '9') >> split(3,4) | # Lagos, Ibadan and Abuja
314
+ match(/^(702\d)\d+$/) >> split(3,4) | # Mobile
315
+ match(/^(70[3-9])\d+$/) >> split(3,4) | # Mobile
316
+ match(/^(8[01]\d)\d+$/) >> split(3,4) | # Mobile
317
+ fixed(2) >> split(3,4) # 2-digit NDC
318
+
319
+ country '235', none >> split(4,4) # Chad http://www.wtng.info/wtng-235-td.html
320
+ country '236', none >> split(4,4) # Central African Republic http://www.wtng.info/wtng-236-cf.html
321
+ country '237', none >> split(4,4) # Cameroon http://www.wtng.info/wtng-237-cm.html
322
+ country '238', none >> split(3,4) # Cape Verde http://www.wtng.info/wtng-238-cv.html
323
+ country '239', fixed(1) >> split(3,3) # Sao Tome and Principe, http://www.wtng.info/wtng-239-st.html
324
+
325
+ country '240', none >> split(3,3,3) # Equatorial Guinea
326
+ country '241', fixed(1) >> split(3,3) # Gabonese Republic http://www.wtng.info/wtng-241-ga.html
327
+ country '242', none >> split(4,5) # Congo http://www.wtng.info/wtng-242-cg.html
328
+ country '243', fixed(1) >> split(3,4) # Democratic Republic of the Congo http://www.wtng.info/wtng-243-cd.html
329
+ country '244', one_of('321', '348', '358', '363', '364', '485', '526', '535', '546', '612', '643', '652', '655', '722', '726', '728', '729', '777') >> split(3,3) | # Angola
330
+ fixed(2) >> split(3,4)
331
+ country '245', none >> split(3,4) # Guinea-Bissau http://www.wtng.info/wtng-245-gw.html
332
+ country '246', none >> split(3,4) # Diego Garcia http://www.wtng.info/wtng-246-io.html
302
333
  country '247', none >> split(4) # Ascension
303
- country '248', todo # Seychelles
334
+
335
+ country '248', # Seychelles
336
+ fixed(1) >> split(2,2,2)
337
+
304
338
  country '249', fixed(2) >> split(3,4) # Sudan
305
339
 
306
340
  # Rwanda
307
341
  # http://en.wikipedia.org/wiki/Telephone_numbers_in_Rwanda
308
342
  country '250',
309
- one_of('25') >> split(7) | # Geographic, fixed
310
- match(/^(7[238])/) >> split(7) | # Non-geographic, mobile
311
- one_of('06') >> split(6) # Satellite
343
+ one_of('25') >> split(7) | # Geographic, fixed
344
+ match(/^(7[238])/) >> split(7) | # Non-geographic, mobile
345
+ one_of('06') >> split(6) # Satellite
312
346
 
313
- country '251', todo # Ethiopia
314
- country '252', todo # Somali Democratic Republic
315
- country '253', todo # Djibouti
347
+ country '251', fixed(2) >> split(3, 4) # Ethiopia http://www.wtng.info/wtng-251-et.html
348
+
349
+ # country '252' # Somali Democratic Republic, see special file
350
+
351
+ country '253', none >> split(4, 4) # Djibouti http://www.wtng.info/wtng-253-dj.html
316
352
 
317
353
  # Kenya
318
354
  # http://en.wikipedia.org/wiki/Telephone_numbers_in_Kenya
@@ -333,8 +369,23 @@ Phony.define do
333
369
  match(/^(46[45]|4[78]\d)/) >> split(6) | # Geo 1.
334
370
  fixed(2) >> split(7) # Geo 2.
335
371
 
336
- country '257', todo # Burundi
337
- country '258', todo # Mozambique
372
+ country '257', none >> split(4,4) # Burundi http://www.wtng.info/wtng-257-bi.html
373
+
374
+ # Mozambique, https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=MZ
375
+ country '258',
376
+ one_of('600') >> split(3,3) | # audiotext
377
+ one_of('610') >> split(3,3) | # ISP
378
+ one_of('800') >> split(3,3) | # freephone
379
+ one_of('801') >> split(3,3) | # local rate
380
+ one_of('802') >> split(3,3) | # national rate
381
+ one_of(%w(251 252 271 272 281 282 293)) >> split(3,2) |
382
+ one_of(%w(21 23 24 26)) >> split(3,3) |
383
+ one_of(%w(82 84 86)) >> split(4,3) | # mobile
384
+ one_of('89') >> split(4,3) | # satellite GMPCS
385
+ one_of('7') >> split(4,4) | # universal access
386
+ one_of('9') >> split(4,4) | # premium rate
387
+ fixed(2) >> split(3,3)
388
+
338
389
  country '259', todo # -
339
390
 
340
391
  # Zambia
@@ -343,15 +394,78 @@ Phony.define do
343
394
  match(/^(9[567])/) >> split(7) | # Mobile
344
395
  match(/^(21[1-8])/) >> split(6) # Geographic
345
396
 
346
- country '261', todo # Madagascar
347
- country '262', todo # Reunion / Mayotte (new)
348
- country '263', todo # Zimbabwe
349
- country '264', todo # Namibia
350
- country '265', todo # Malawi
351
- country '266', todo # Lesotho
352
- country '267', todo # Botswana
353
- country '268', todo # Swaziland
354
- country '269', todo # Comoros
397
+ # Madagascar http://www.wtng.info/wtng-261-mg.html
398
+ # http://www.itu.int/oth/T020200007F/en
399
+ country '261',
400
+ none >> matched_split(
401
+ /\A200\d+\z/ => [2,3,3,3], # Telecom Malagasy (Telma)
402
+ /\A20\d+\z/ => [2,3,4], # Telecom Malagasy (Telma)
403
+ /\A23\d+\z/ => [2,3,4], # Digitel
404
+ /\A30\d+\z/ => [2,3,4], # mobile Madamobil (CDMA2000)
405
+ /\A31\d+\z/ => [2,3,4], # mobile Sacel
406
+ /\A32\d+\z/ => [2,3,4], # mobile Orange Madagascar
407
+ /\A34\d+\z/ => [2,3,4], # mobile Telecom Malagasy (Telma)
408
+ /\A5\d+\z/ => [3,3,3], # pager
409
+ /\A22\d+\z/ => [3,3,3], # satellite GULFSAT Téléphonie
410
+ /\A6\d+\z/ => [3,3,3] # satellite
411
+ )
412
+
413
+ country '262', none >> split(5, 5) # Reunion / Mayotte (new) http://www.wtng.info/wtng-262-fr.html
414
+
415
+ # country '263' # Zimbabwe, see special file
416
+
417
+ # country '264' # Namibia, see special file
418
+
419
+ # Malawi
420
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=MW
421
+ country '265',
422
+ none >> matched_split(
423
+ /\A(21|77)\d+\z/ => [3,3,3], # geographic, mobile
424
+ /\A(88|99)\d{7}\z/ => [3,3,3], # mobile
425
+ /\A18(00|11|18|20)\z/ => [4], # ISP
426
+ /\A\d+\z/ => [4,3]
427
+ )
428
+
429
+ country '266', none >> split(4, 4) # Lesotho http://www.wtng.info/wtng-266-ls.html
430
+
431
+ # Botswana
432
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
433
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=BW
434
+ country '267',
435
+ one_of(%w(463 495 499 590)) >> split(4) |
436
+ one_of(%w(24 26 29 31 46 47 49 53 54 57 58 59 62 65 68)) >> split(3,2) |
437
+ one_of('79') >> split(3,3) | # VoIP telephony
438
+ one_of('80') >> split(3,3) | # freephone
439
+ one_of('90') >> split(3,3) | # premium rate
440
+ one_of('7') >> split(4,3) | # moblie
441
+ one_of('8') >> split(4,3) | # shared cost
442
+ one_of('3') >> split(3,3) |
443
+ fixed(2) >> split(3,2)
444
+
445
+ # Swaziland http://www.wtng.info/wtng-268-sz.html
446
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=SZ
447
+ country '268',
448
+ none >> matched_split(
449
+ /\A08\d+\z/ => [4,3], # freephone
450
+ /\A(2200|2300|2538|2548)\d+\z/ => [4,4], # VoIP telephony Swaziland Posts and Telecommunications Corporation (SPTC)
451
+ /\A(2400|76)\d+\z/ => [4,4], # mobile Swazi MTN Ltd
452
+ /\A(2550|2551)\d+\z/ => [4,4], # wireless geographic Swaziland Posts and Telecommunications Corporation (SPTC)
453
+ /\A(550|551)\d+\z/ => [3,4], # wireless geographic Swaziland Posts and Telecommunications Corporation (SPTC)
454
+ /\A(22|23|24|25)\d+\z/ => [4,4], # geographic SPTC
455
+ /\A77\d+\z/ => [4,4], # mobile Swaziland Posts and Telecommunications Corporation (SPTC) (CDMA)
456
+ /\A78\d+\z/ => [4,4], # mobile Swazi MTN Ltd
457
+ )
458
+
459
+ # Comoros http://www.wtng.info/wtng-269-km.html
460
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=KM
461
+ country '269',
462
+ none >> matched_split(
463
+ /\A800\d+\z/ => [4,3,3], # freephone Toll-free Global269
464
+ /\A(763|77)\d+\z/ => [4,3], # geographic Comores Télécom
465
+ /\A(32|33|34)\d+\z/ => [4,3], # mobile Comores Télécom (HURI)
466
+ /\A(390|391|900|910)\d+\z/ => [4,3], # premium rate WIAIR SARL
467
+ /\A(76)\d+\z/ => [4,3] # wireless geographic Comores Télécom
468
+ )
355
469
 
356
470
  country '280', todo # -
357
471
  country '281', todo # -
@@ -363,23 +477,39 @@ Phony.define do
363
477
  country '287', todo # -
364
478
  country '288', todo # -
365
479
  country '289', todo # -
366
- country '290', todo # Saint Helena
367
-
368
- country '291', todo # Eritrea
480
+ country '290', none >> split(4) # Saint Helena http://www.wtng.info/wtng-290-sh.html
481
+ country '291', fixed(1) >> split(3, 3) # Eritrea http://www.wtng.info/wtng-291-er.html
369
482
  country '292', todo # -
370
483
  country '293', todo # -
371
484
  country '294', todo # -
372
485
  country '295', todo # -
373
486
  country '296', todo # -
374
- country '297', todo # Aruba
375
- country '298', todo # Faroe Islands
376
- country '299', todo # Greenland
487
+ country '297', fixed(2) >> split(4) # Aruba
488
+
489
+ # Faroe Islands http://www.wtng.info/wtng-298-fo.html
490
+ country '298',
491
+ none >> matched_split(
492
+ /\A1\d+\z/ => [4], # universal access: Føroya Tele; ISP: Kall, Føroya Tele
493
+ /\A\d+\z/ => [3,3]
494
+ )
495
+
496
+ # Greenland http://www.wtng.info/wtng-299-gl.html
497
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
498
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=GL
499
+ country '299',
500
+ one_of(%w(199 691)) >> split(3) | # satellite; geographic: Ivittuut
501
+ one_of(%w(31 32 33 34 35 36 61 64 66 68 81 84 85 86 87 89 91 92 94 95 96 97 98 99)) >> split(4) | # geographic
502
+ one_of(%w(22 23 24 25 26 27 28 29 42 43 44 45 46 47 48 49 52 53 54 55 56 57 58 59)) >> split(4) | # mobile: Tele Greenland A/S
503
+ one_of(%w(38 39)) >> split(4) | # VoIP telephony
504
+ match(/\A(50)\d{4}\z/) >> split(4) | #| voicemail (mobile) Tele Greenland A/S
505
+ match(/\A(50)\d{6}\z/) >> split(3,3) | #|
506
+ fixed(2) >> split(4)
377
507
 
378
508
  # Gibraltar
379
509
  country '350',
380
510
  match(/^(2[012]\d)\d+$/) >> split(5) | # fixed
381
- match(/^([56]\d)\d+$/) >> split(6) | # mobile
382
- match(/^(8\d\d\d)$/) >> split(0)
511
+ match(/^([56]\d)\d+$/) >> split(6) | # mobile
512
+ match(/^(8\d\d\d)$/) >> split(0)
383
513
 
384
514
  # Portugal.
385
515
  #
@@ -392,16 +522,18 @@ Phony.define do
392
522
  # Luxembourg
393
523
  #
394
524
  country '352',
395
- one_of('4') >> split(2,2,2) | # Luxembourg City
396
- match(/^(2[467]\d{2})$/) >> split(2,2,2) | # 4-digit NDC
397
- match(/^(6\d[18])\d+$/) >> split(3,3) | # mobile
398
- match(/^(60\d{2})\d{8}$/) >> split(2,2,2,2) | # mobile machine to machine
399
- match(/^([2-9]\d)/) >> split(2,2,2) # 2-digit NDC
525
+ one_of('4') >> split(2,2,2) | # Luxembourg City
526
+ match(/^(2[467]\d{2})$/) >> split(2,2,2) | # 4-digit NDC
527
+ match(/^(6\d[18])\d+$/) >> split(3,3) | # mobile
528
+ match(/^(60\d{2})\d{8}$/) >> split(2,2,2,2) | # mobile machine to machine
529
+ match(/^([2-9]\d)/) >> split(2,2,2) # 2-digit NDC
400
530
 
401
531
  # country '353' # Republic of Ireland, see special file.
402
532
 
403
533
  country '354', none >> split(3,4) # Iceland
404
- country '355', todo # Albania
534
+ country '355', one_of('4') >> split(4,3) | # Albania
535
+ match(/\A(2[24]|3[2-5]|47|5[2-5]|6[6-9]|8[2-5])\d*\z/) >> split(3,3) |
536
+ fixed(3) >> split(3,2)
405
537
 
406
538
  # Malta
407
539
  # http://en.wikipedia.org/wiki/Telephone_numbers_in_Malta
@@ -410,13 +542,12 @@ Phony.define do
410
542
  match(/^(2\d\d\d)\d+$/) >> split(4) | # fixed line
411
543
  fixed(4) >> split(4) # eg. with voice mail
412
544
 
413
-
414
545
  # Cyprus
415
546
  # http://www.cytaglobal.com/cytaglobal/userfiles/NewNumberingPlan.pdf
416
547
  country '357', one_of('121','122','123') >> split(2,6) | # voicemail
417
548
  fixed(2) >> split(6) # fixed & mobile
418
549
 
419
- # Finland.
550
+ # Finland
420
551
  #
421
552
  country '358',
422
553
  match(/^([6-8]00)\d+$/) >> split(3,3) | # Service
@@ -424,57 +555,74 @@ Phony.define do
424
555
  one_of('2','3','5','6','8','9') >> split(3,3) | # Short NDCs
425
556
  fixed(2) >> split(3,3) # 2-digit NDCs
426
557
 
427
- # Bulgaria.
558
+ # Bulgaria
428
559
  #
429
560
  country '359',
430
561
  fixed(2) >> split(3,2,2) # Bulgaria
431
562
 
432
- # Lithuania.
563
+ # Lithuania
433
564
  #
434
565
  country '370',
435
- one_of('700', '800') >> split(2,3) | # Service
436
- match(/^(6\d\d)\d+$/) >> split(2,3) | # Mobile
437
- one_of('5') >> split(3,2,2) | # Vilnius
438
- one_of('37','41') >> split(2,2,2) | # Kaunas, Šiauliai
439
- fixed(3) >> split(1,2,2) # 3-digit NDCs.
566
+ one_of('700', '800') >> trunk('8') >> split(2,3) | # Service
567
+ match(/^(6\d\d)\d+$/) >> trunk('8') >> split(2,3) | # Mobile
568
+ one_of('5') >> trunk('8') >> split(3,2,2) | # Vilnius
569
+ one_of('37','41') >> trunk('8') >> split(2,2,2) | # Kaunas, Šiauliai
570
+ fixed(3) >> trunk('8') >> split(1,2,2) # 3-digit NDCs.
440
571
 
441
- country '371', todo # Latvia
572
+ # country '371' # Latvia, see special file
442
573
 
443
574
  # Estonia
575
+ #
444
576
  country '372',
445
- match(/^((5\d|8[12])\d\d)\d+$/) >> split(4) | # Mobile
446
- fixed(3) >> split(4) # 3-digit NDCs
577
+ match(/^(5\d\d\d)\d+$/) >> split(4) | # Mobile
578
+ match(/^((?:70|8[12])\d\d)\d+$/) >> split(4) | # Mobile
579
+ fixed(3) >> split(4) # 3-digit NDCs
580
+
581
+ # country '373' # Moldova, see special file
582
+
583
+ country '374', match(/\A(10|55|77|9[13-9])\d*\z/) >> split(6) | # Armenia
584
+ fixed(3) >> split(5)
447
585
 
448
- country '373', todo # Moldova
449
- country '374', todo # Armenia
450
- country '375', todo # Belarus
451
- country '376', todo # Andorra
586
+ # Belarus
587
+ # country '375' # see special file
588
+
589
+ country '376', fixed(1) >> split(5) # Andorra
452
590
 
453
591
  # Monaco
592
+ #
454
593
  country '377',
455
594
  one_of('6') >> split(2,2,2,2) | # mobile
456
595
  fixed(2) >> split(2,2,2)
457
596
 
458
- country '378', todo # San Marino
597
+ # San Marino
598
+ country '378',
599
+ none >> matched_split(
600
+ /\A\d{6}\z/ => [3,3],
601
+ /\A\d+\z/ => [3,3,4]
602
+ )
603
+
459
604
  country '379', todo # Vatican City State
460
605
 
461
- country '380', todo # Ukraine
462
- country '381', todo # Serbia and Montenegro
463
- country '382', todo # -
606
+ # country '380' # Ukraine, see special file
607
+
608
+ # country '381' # Serbia, see special file
609
+
610
+ # country '382' # Montenegro, see special file
611
+
464
612
  country '383', todo # -
465
613
  country '384', todo # -
466
614
 
467
615
  # Croatia.
468
616
  #
469
- country '385', one_of('1') >> split(3,5) | # Zagreb
470
- fixed(2) >> split(3,5) # 2-digit NDCs
617
+ country = country '385', one_of('1') >> split(3, 5) | # Zagreb
618
+ fixed(2) >> split(3, 5) # 2-digit NDCs
471
619
 
472
- country '386', fixed(2) >> split(3,2,2) # Slovenia
620
+ country '386', fixed(2) >> split(3, 2, 2) # Slovenia
473
621
  country '387', fixed(2) >> split(3,2,2) # Bosnia and Herzegovina
474
622
  country '388', fixed(2) >> split(3,2,2) # Group of countries, shared code
475
623
  country '389', fixed(2) >> split(3,2,2) # The Former Yugoslav Republic of Macedonia
476
624
 
477
- country '420', fixed(3) >> split(3,3) # Czech Republic
625
+ country '420', fixed(3) >> split(3,3) # Czech Republic
478
626
 
479
627
  # Slovak Republic.
480
628
  #
@@ -491,53 +639,166 @@ Phony.define do
491
639
  country '428', todo # -
492
640
  country '429', todo # -
493
641
 
494
- country '500', todo # Falkland Islands (Malvinas)
495
- country '501', todo # Belize
496
- country '502', todo # Guatemala (Republic of)
497
- country '503', todo # El Salvador (Republic of)
498
- country '504', todo # Honduras (Republic of)
499
- country '505', todo # Nicaragua
500
- country '506', todo # Costa Rica
501
- country '507', todo # Panama (Republic of)
502
- country '508', todo # Saint Pierre and Miquelon (Collectivité territoriale de la République française)
503
- country '509', todo # Haiti (Republic of)
504
-
505
- country '590', todo # Guadeloupe (French Department of)
506
- country '591', todo # Bolivia (Republic of)
507
- country '592', todo # Guyana
508
- country '593', todo # Ecuador
509
- country '594', todo # French Guiana (French Department of)
510
- country '595', todo # Paraguay (Republic of)
511
- country '596', todo # Martinique (French Department of)
512
- country '597', todo # Suriname (Republic of)
513
- country '598', todo # Uruguay (Eastern Republic of)
514
- country '599', todo # Netherlands Antilles
515
-
516
- country '670', todo # Democratic Republic of Timor-Leste
642
+ country '500', none >> split(2,3) # Falkland Islands (Malvinas) http://www.wtng.info/wtng-500-fk.html
643
+ country '501', fixed(3) >> split(4) # Belize
644
+
645
+ # Guatemala (Republic of) http://www.wtng.info/wtng-502-gt.html
646
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
647
+ #
648
+ country '502',
649
+ one_of('19') >> split(3,3,3) | # premium rate
650
+ fixed(1) >> split(3,4)
651
+
652
+ # El Salvador (Republic of)
653
+ country '503', fixed(4) >> split(4,4)
654
+
655
+ # Honduras (Republic of) http://www.wtng.info/wtng-504-hn.html
656
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
657
+ country '504',
658
+ one_of('800') >> split(3,4) | # freephone
659
+ fixed(2) >> split(3,3) # geographic, mobile
660
+
661
+ # Nicaragua http://www.wtng.info/wtng-505-ni.html
662
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
663
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=NI
664
+ country '505',
665
+ one_of('9') >> split(3,3) | # premium rate
666
+ fixed(2) >> split(3,3) # geographic, mobile
667
+
668
+ # Costa Rica http://www.wtng.info/wtng-506-cr.html
669
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
670
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=CR
671
+ country '506',
672
+ one_of('800') >> split(3,4) | # freephone
673
+ one_of(%w(905 909)) >> split(3,4) | # premium rate
674
+ fixed(1) >> split(3,4) # geographic
675
+
676
+ # Panama (Republic of) http://www.wtng.info/wtng-507-pa.html
677
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
678
+ country '507',
679
+ one_of(%w(800 809)) >> split(4) | # freephone
680
+ one_of('6') >> split(3,4) | # mobile
681
+ fixed(1) >> split(3,3) # geographic, VoIP telephony, mobile, premium rate, shared cost, pager
682
+
683
+ country '508', none >> split(3, 3) # Saint Pierre and Miquelon (Collectivité territoriale de la République française) http://www.wtng.info/wtng-508-pm.html
684
+
685
+ country '509', # Haiti (Republic of)
686
+ fixed(2) >> split(2,4)
687
+
688
+ # Guadeloupe (French Department of) http://www.wtng.info/wtng-590-fr.html
689
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
690
+ country '590', fixed(3) >> split(3,3)
691
+
692
+ country '591', fixed(1) >> split(3,4) # Bolivia (Republic of) http://www.itu.int/oth/T020200001A/en
693
+
694
+ # Guyana http://www.wtng.info/wtng-592-gy.html
695
+ # https://www.numberingplans.com
696
+ country '592',
697
+ one_of('10') >> split(2) | # audiotext
698
+ one_of(%w(11 16 17 18 19)) >> split(3) | # audiotext
699
+ fixed(3) >> split(4) # geographic, audiotext
700
+
701
+ country '593', fixed(2) >> split(3, 4) # Ecuador http://www.wtng.info/wtng-593-ec.html
702
+ country '594', fixed(3) >> split(3, 3) # French Guiana (French Department of) http://www.wtng.info/wtng-594-fr.html
703
+
704
+ # country '595' # Paraguay (Republic of), see special file
705
+
706
+ # Martinique (French Department of) http://www.wtng.info/wtng-596-mq.html, https://www.numberingplans.com
707
+ country '596', fixed(3) >> split(3, 3)
708
+
709
+ # Suriname (Republic of) http://www.wtng.info/wtng-597-sr.html, https://www.numberingplans.com
710
+ country '597',
711
+ none >> matched_split(
712
+ /\A[6789]\d+\z/ => [3,4], # freephone, mobile
713
+ /\A[2345]\d+\z/ => [3,3], # geographic, VoIP telephony
714
+ )
715
+
716
+ # country '598' # Uruguay (Eastern Republic of), see special file
717
+
718
+ country '599', one_of('9') >> split(3,4) | # Netherlands Antilles (Curacao)
719
+ fixed(3) >> split(4) # (other)
720
+
721
+ # Democratic Republic of Timor-Leste http://www.wtng.info/wtng-670-tl.html
722
+ country '670',
723
+ none >> matched_split(
724
+ /\A7\d+\z/ => [4,4], # mobile
725
+ /\A\d+\z/ => [3,4]
726
+ )
727
+
517
728
  country '671', todo # Spare code
518
729
  country '672', todo # Australian External Territories
519
- country '673', todo # Brunei Darussalam
520
- country '674', todo # Nauru (Republic of)
521
- country '675', todo # Papua New Guinea
522
- country '676', todo # Tonga (Kingdom of)
523
- country '677', todo # Solomon Islands
524
- country '678', todo # Vanuatu (Republic of)
525
- country '679', todo # Fiji (Republic of)
526
-
527
- country '680', todo # Palau (Republic of)
730
+ country '673', fixed(1) >> split(3, 3) # Brunei Darussalam http://www.wtng.info/wtng-673-bn.html
731
+ country '674', none >> split(3, 4) # Nauru (Republic of) http://www.wtng.info/wtng-674-nr.html
732
+
733
+ # Papua New Guinea
734
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=PG
735
+ country '675',
736
+ one_of(%w(180 181 182 183)) >> split(4) | # freephone
737
+ one_of('170') >> split(2) | # mobile
738
+ one_of('189') >> split(1) | # mobile
739
+ one_of('184') >> split(4,4) | # ISP, PSDN X.28
740
+ one_of(%w(185 270 271)) >> split(4) | # pager
741
+ one_of(%w(275 276)) >> split(4) | # satellite
742
+ one_of(%w(278 279)) >> split(2) | # satellite
743
+ one_of('115') >> split(4,4) | # voicemail (mobile)
744
+ one_of(%w(28 29)) >> split(3,2) | # pager
745
+ one_of(%w(16 18)) >> split(3,2) | # ISP
746
+ one_of(%w(71 72 73 76)) >> split(3,3) | # mobile
747
+ one_of(%w(80 81 82 83)) >> split(3,3) | # freephone
748
+ one_of(%w(90 91 92 93)) >> split(3,3) | # geographic, ISDN
749
+ one_of(%w(3 4 5 6 7 8 9)) >> split(3,3) # geographic
750
+ fixed(1) >> split(3,3) # geographic
751
+
752
+ # Tonga (Kingdom of)
753
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=TO
754
+ country '676',
755
+ none >> matched_split(
756
+ /\A(77|78|87|88|89)\d+\z/ => [2,3,2],
757
+ /\A\d+\z/ => [2,3]
758
+ )
759
+
760
+ # Solomon Islands http://www.wtng.info/wtng-677-sb.html, https://www.numberingplans.com
761
+ country '677',
762
+ none >> matched_split(
763
+ /\A7\d+\z/ => [4,3], # mobile
764
+ /\A\d+\z/ => [2,3] # freephone, geographic, mobile, VoIP telephony
765
+ )
766
+
767
+ # Vanuatu (Republic of) http://www.wtng.info/wtng-678-vu.html, https://www.numberingplans.com
768
+ country '678',
769
+ none >> matched_split(
770
+ /\A[579]\d+\z/ => [4,3], # mobile
771
+ /\A\d+\z/ => [2,3] # geographic, VoIP telephony
772
+ )
773
+
774
+ country '679', none >> split(3, 4) # Fiji (Republic of) http://www.wtng.info/wtng-679-fj.html
775
+
776
+ country '680', none >> split(3, 4) # Palau (Republic of) http://www.wtng.info/wtng-680-pw.html
528
777
  country '681', todo # Wallis and Futuna (Territoire français d'outre-mer)
529
- country '682', todo # Cook Islands
530
- country '683', todo # Niue
778
+ country '682', none >> split(2,3) # Cook Islands http://www.wtng.info/wtng-682-ck.html
779
+ country '683', none >> split(4) # Niue http://www.wtng.info/wtng-683-nu.html
531
780
  country '684', todo # -
532
- country '685', todo # Samoa (Independent State of)
533
- country '686', todo # Kiribati (Republic of)
534
- country '687', todo # New Caledonia (Territoire français d'outre-mer)
535
- country '688', todo # Tuvalu
536
- country '689', todo # French Polynesia (Territoire français d'outre-mer)
537
-
538
- country '690', todo # Tokelau
539
- country '691', todo # Micronesia (Federated States of)
540
- country '692', todo # Marshall Islands (Republic of the)
781
+
782
+ # Samoa (Independent State of)
783
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=WS
784
+ country '685',
785
+ none >> matched_split(
786
+ /\A800\d+\z/ => [3,3], # freephone
787
+ /\A830\d+\z/ => [3,3], # shared cost
788
+ /\A60\d+\z/ => [3,3], # wireless geographic
789
+ /\A(72|75|76|77)\d+\z/ => [3,4], # mobile
790
+ /\A84\d+\z/ => [3,4], # wireless geographic
791
+ /\A\d+\z/ => [2,3] # geographic
792
+ )
793
+
794
+ country '686', none >> split(2,3) # Kiribati (Republic of) http://www.wtng.info/wtng-686-ki.html
795
+ country '687', none >> split(3,3) # New Caledonia (Territoire français d'outre-mer) http://www.wtng.info/wtng-687-nc.html
796
+ country '688', none >> split(5) # Tuvalu http://www.wtng.info/wtng-688-tv.html
797
+ country '689', none >> split(3,3) # French Polynesia (Territoire français d'outre-mer) http://www.wtng.info/wtng-689-pf.html
798
+
799
+ country '690', fixed(1) >> split(3) # Tokelau http://www.wtng.info/wtng-690-tk.html
800
+ country '691', none >> split(3, 4) # Micronesia (Federated States of) http://www.wtng.info/wtng-691-fm.html
801
+ country '692', none >> split(3, 4) # Marshall Islands (Republic of the) http://www.wtng.info/wtng-692-mh.html
541
802
  country '693', todo # -
542
803
  country '694', todo # -
543
804
  country '695', todo # -
@@ -568,9 +829,25 @@ Phony.define do
568
829
  country '838', todo # -
569
830
  country '839', todo # -
570
831
 
571
- country '850', todo # Democratic People's Republic of Korea
832
+ # Democratic People's Republic of Korea
833
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=KP
834
+ country '850',
835
+ one_of(%w(191 192 193)) >> split(3,4) | # mobile
836
+ one_of('2') >> matched_split(
837
+ /\A\d{5}\z/ => [3,2],
838
+ /\A\d{7}\z/ => [3,4],
839
+ #/\A(880|881|882|883|885)\d+\z/ => [4,4,4,4],
840
+ /\A\d+\z/ => [3,3,3]) |
841
+ one_of(%w(31 39 41 45 53 57 61 67 73 79)) >> split(3,3) |
842
+ fixed(2) >> split(3,3)
843
+
572
844
  country '851', todo # Spare code
573
- country '852', todo # Hong Kong, China
845
+
846
+ # Hong Kong, China
847
+
848
+ country '852',
849
+ none >> split(4,4)
850
+
574
851
  country '853', todo # Macao, China
575
852
  country '854', todo # Spare code
576
853
 
@@ -579,7 +856,12 @@ Phony.define do
579
856
  country '855',
580
857
  fixed(2) >> split(3,4)
581
858
 
582
- country '856', todo # Lao People's Democratic Republic
859
+ # Lao People's Democratic Republic http://www.wtng.info/wtng-856-la.html, https://www.numberingplans.com
860
+ country '856',
861
+ one_of('30') >> split(3,4) | # geographic
862
+ one_of('20') >> split(4,4) | # mobile
863
+ fixed(2) >> split(3,3) # geographic
864
+
583
865
  country '857', todo # Spare code
584
866
  country '858', todo # Spare code
585
867
  country '859', todo # Spare code
@@ -595,13 +877,17 @@ Phony.define do
595
877
  country '878', todo # Universal Personal Telecommunication Service (UPT)
596
878
  country '879', todo # Reserved for national non-commercial purposes
597
879
 
598
- country '880', todo # Bangladesh (People's Republic of)
880
+ # Bangladesh (People's Republic of)
881
+ # country '880' # see special file
882
+
599
883
  country '881', todo # International Mobile, shared code
600
884
  country '882', todo # International Networks, shared code
601
885
  country '883', todo # -
602
886
  country '884', todo # -
603
887
  country '885', todo # -
604
- country '886', todo # Reserved
888
+
889
+ # country '886' # Taiwan, see special file
890
+
605
891
  country '887', todo # -
606
892
  country '888', todo # Reserved for future global service
607
893
  country '889', todo # -
@@ -617,36 +903,149 @@ Phony.define do
617
903
  country '898', todo # -
618
904
  country '899', todo # -
619
905
 
620
- country '960', todo # Maldives (Republic of)
621
- country '961', todo # Lebanon
622
- country '962', todo # Jordan (Hashemite Kingdom of)
623
- country '963', todo # Syrian Arab Republic
624
- country '964', todo # Iraq (Republic of)
625
- country '965', todo # Kuwait (State of)
626
- country '966', todo # Saudi Arabia (Kingdom of)
627
- country '967', todo # Yemen (Republic of)
628
- country '968', todo # Oman (Sultanate of)
906
+ # Maldives (Republic of) http://www.wtng.info/wtng-960-mv.html, https://www.numberingplans.com
907
+ country '960',
908
+ one_of(%w(800 900)) >> split(3,4) | # freephone, premium rate
909
+ fixed(3) >> split(4) # geographic, mobile
910
+
911
+ # Lebanon
912
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
913
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=LB
914
+ country '961',
915
+ one_of(%w(70 71 76 78 79)) >> split(3,3) | # mobile
916
+ one_of(%w(90 91)) >> split(3,3) | # premium rate
917
+ one_of(%w(80 81)) >> split(3,3) | # shared cost
918
+ one_of(%w(1 4 5 6 7 8 9)) >> split(3,3) | # geographic
919
+ one_of('3') >> split(3,3) | # mobile
920
+ fixed(1) >> split(3,3)
921
+
922
+ # Jordan (Hashemite Kingdom of)
923
+ country '962',
924
+ one_of(%w(6250 8790)) >> split(4) | # wireless geographic
925
+ one_of(%w(800 801 802 803 804 805 806 807 808 809)) >> split(3,2) | # freephone
926
+ one_of('810') >> split(3,2) | # ISP
927
+ one_of('900') >> split(3,2) | # premium rate
928
+ one_of('70') >> split(3,3) | # universal access
929
+ one_of(%w(85 87)) >> split(3,3) | # shared cost
930
+ one_of(%w(2 3 5 6)) >> split(3,4) | # geographic
931
+ one_of('7') >> split(4,4) | # mobile, pager
932
+ fixed(1) >> split(3,4)
933
+
934
+ # Syrian Arab Republic
935
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=SY
936
+ country '963',
937
+ one_of(%w(11 14 31 33)) >> split(3,4) |
938
+ one_of(%w(12 13 15 16 21 22 23 25 34 41 43 51 52 53)) >> split(3,3) |
939
+ one_of('4') >> split(3,4) |
940
+ one_of('9') >> split(4,4) | # mobile
941
+ fixed(2) >> split(3,3)
942
+
943
+ # Iraq (Republic of)
944
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
945
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=IQ
946
+ country '964',
947
+ one_of(%w(21 23 24 25 30 32 33 36 37 40 42 43 50 53 60 62 66)) >> split(3,3) |
948
+ one_of(%w(71 72 73 74 75 76 77 78 79)) >> split(4,4) | # mobile
949
+ one_of('1') >> split(3,4) |
950
+ fixed(2) >> split(3,3)
951
+
952
+ # Kuwait (State of) http://www.wtng.info/wtng-965-kw.html
953
+ country '965',
954
+ none >> matched_split(
955
+ /\A65816\d+\z/ => [4,4,4], # voicemail (mobile), Wataniya Telecom
956
+ /\A1\d+\z/ => [3,4], # geographic
957
+ /\A2\d+\z/ => [4,4], # geographic
958
+ /\A[569]\d+\z/ => [4,4], # mobile
959
+ /\A8\d+\z/ => [3,3], # geographic
960
+ )
961
+
962
+ country '966', fixed(1) >> split(3, 4) # Saudi Arabia (Kingdom of) http://www.wtng.info/wtng-966-sa.html
963
+
964
+ # Yemen (Republic of)
965
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
966
+ country '967',
967
+ one_of(%w(70 71 73 77)) >> split(3,4) | # mobile
968
+ one_of('58') >> split(4) | # pager
969
+ one_of('1') >> matched_split(
970
+ /\A\d{6}\z/ => [3,3],
971
+ /\A\d+\z/ => [3,4]) |
972
+ one_of(%w(2 3 4 5 6 7)) >> split(3,3) |
973
+ fixed(1) >> split(3,3)
974
+
975
+ # Oman (Sultanate of), https://www.numberingplans.com/?page=dialling&sub=areacodes
976
+ country '968', fixed(2) >> split(3,3)
977
+
629
978
  country '969', todo # Reserved - reservation currently under investigation
630
979
 
631
- country '970', todo # Reserved
632
- country '971', todo # United Arab Emirates
633
- country '972', todo # Israel (State of)
634
- country '973', todo # Bahrain (Kingdom of)
635
- country '974', todo # Qatar (State of)
636
- country '975', todo # Bhutan (Kingdom of)
637
- country '976', todo # Mongolia
638
- country '977', todo # Nepal
980
+ country '970', # 970 is used in those countries that block access to 972 (Israel)
981
+ one_of('1') >> split(3,3,3) | # special numbers
982
+ one_of('2', '3', '4', '8', '9') >> split(3,4) | # 1 digit ndc
983
+ match(/^(5[023456789]|7[23467])\d+$/) >> split(3,4) # 2 digit ndc
984
+
985
+ # United Arab Emirates
986
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
987
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=AE
988
+ country '971',
989
+ one_of(%w(200 300)) >> split(3,3) | # shared cost
990
+ one_of('600') >> split(3,3) | # national rate
991
+ one_of(%w(500 700 900)) >> split(3,3) | # premium rate
992
+ one_of('800') >> matched_split(
993
+ /\A\d{2}\z/ => [2],
994
+ /\A\d+\z/ => [2,3,4]) | # freephone
995
+ one_of(%w(50 52 55 56)) >> split(3,4) | # mobile
996
+ one_of(%w(2 3 4 6 7 9)) >> split(3,4) |
997
+ fixed(1) >> split(3,4)
998
+
999
+ # Israel (State of) (also works for numbers in Palestinian territories)
1000
+ country '972',
1001
+ one_of('1') >> split(3,3,3) | # special numbers
1002
+ one_of('2', '3', '4', '8', '9') >> split(3,4) | # 1 digit ndc
1003
+ match(/^(5[023456789]|7[23467])\d+$/) >> split(3,4) # 2 digit ndc
1004
+
1005
+ country '973', none >> split(4,4) # Bahrain (Kingdom of) http://www.itu.int/oth/T0202000011/en
1006
+
1007
+ # Qatar (State of)
1008
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=QA
1009
+ country '974',
1010
+ one_of(%w(1245 1744)) >> split(3,3) | # voicemail
1011
+ one_of(%w(800 900)) >> split(2,2) | # freephone, audiotext
1012
+ one_of(%w(20 21 22 26)) >> split(3,2) | # pager
1013
+ one_of(%w(92 97)) >> split(3) | # mobile
1014
+ fixed(2) >> split(3,3)
1015
+
1016
+ country '975', fixed(1) >> split(3, 3) # Bhutan (Kingdom of) http://www.wtng.info/wtng-975-bt.html
1017
+
1018
+ # Mongolia
1019
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=MN
1020
+ country '976',
1021
+ one_of(%w(121 122 123 221 222 223)) >> matched_split(
1022
+ /\A\d{4}\z/ => [2,2],
1023
+ /\A\d+\z/ => [2,3]) |
1024
+ one_of(%w(11 12 13 14 15 21 22 23 24 25)) >> split(3,2) |
1025
+ one_of(%w(70 75 76 77 78 79)) >> split(3,3) | # VoIP telephony
1026
+ one_of(%w(88 89 90 91 94 95 96 99)) >> split(3,3) | # mobile
1027
+ one_of(%w(50 55 56 58 92)) >> split(3,3) | # wireless geographic
1028
+ fixed(2) >> split(3,3)
1029
+
1030
+ # country '977' # Nepal, see special file
1031
+
639
1032
  country '978', todo # -
640
1033
  country '979', todo # International Premium Rate Service (IPRS)
641
1034
 
642
1035
  country '990', todo # Spare code
643
1036
  country '991', todo # Trial of a proposed new international telecommunication public correspondence service, shared code
644
- country '992', todo # Tajikistan (Republic of)
645
- country '993', todo # Turkmenistan
646
- country '994', todo # Azerbaijani Republic
647
- country '995', todo # Georgia
648
- country '996', todo # Kyrgyz Republic
1037
+
1038
+ # country '992' # Tajikistan (Republic of), see special file
1039
+
1040
+ # country '993' # Turkmenistan, see special file
1041
+
1042
+ country '994', fixed(2) >> split(7) # Azerbaijani Republic
1043
+
1044
+ # country '995' # Georgia, see special file
1045
+
1046
+ # country '996' # Kyrgyz Republic, see special file
1047
+
649
1048
  country '997', todo # Spare code
650
- country '998', todo # Uzbekistan (Republic of)
1049
+ country '998', fixed(2) >> split(3, 4) # Uzbekistan (Republic of) http://www.wtng.info/wtng-998-uz.html
651
1050
  country '999', todo # Reserved for possible future use within the Telecommunications for Disaster Relief (TDR) concept
652
1051
  end