phony 2.15.0 → 2.20.1
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.
- checksums.yaml +5 -5
- data/README.textile +35 -7
- data/lib/phony/config.rb +91 -0
- data/lib/phony/countries/argentina.rb +355 -0
- data/lib/phony/countries/austria.rb +34 -24
- data/lib/phony/countries/bangladesh.rb +2 -0
- data/lib/phony/countries/belarus.rb +2 -0
- data/lib/phony/countries/brazil.rb +6 -4
- data/lib/phony/countries/cambodia.rb +6 -4
- data/lib/phony/countries/china.rb +7 -2
- data/lib/phony/countries/croatia.rb +13 -16
- data/lib/phony/countries/georgia.rb +6 -4
- data/lib/phony/countries/germany.rb +5 -2
- data/lib/phony/countries/guinea.rb +8 -5
- data/lib/phony/countries/india.rb +2 -0
- data/lib/phony/countries/indonesia.rb +8 -3
- data/lib/phony/countries/ireland.rb +27 -23
- data/lib/phony/countries/italy.rb +30 -17
- data/lib/phony/countries/japan.rb +61 -8
- data/lib/phony/countries/kyrgyzstan.rb +2 -0
- data/lib/phony/countries/latvia.rb +2 -0
- data/lib/phony/countries/libya.rb +3 -1
- data/lib/phony/countries/malaysia.rb +22 -2
- data/lib/phony/countries/moldova.rb +2 -0
- data/lib/phony/countries/montenegro.rb +2 -0
- data/lib/phony/countries/myanmar.rb +2 -0
- data/lib/phony/countries/namibia.rb +2 -0
- data/lib/phony/countries/nepal.rb +2 -0
- data/lib/phony/countries/netherlands.rb +5 -1
- data/lib/phony/countries/pakistan.rb +2 -0
- data/lib/phony/countries/paraguay.rb +2 -0
- data/lib/phony/countries/russia_kazakhstan_abkhasia_south_ossetia.rb +24 -14
- data/lib/phony/countries/saudi_arabia.rb +40 -0
- data/lib/phony/countries/serbia.rb +10 -4
- data/lib/phony/countries/somalia.rb +5 -1
- data/lib/phony/countries/south_korea.rb +16 -9
- data/lib/phony/countries/sweden.rb +53 -38
- data/lib/phony/countries/taiwan.rb +22 -46
- data/lib/phony/countries/tajikistan.rb +2 -0
- data/lib/phony/countries/turkmenistan.rb +2 -0
- data/lib/phony/countries/ukraine.rb +5 -2
- data/lib/phony/countries/united_kingdom.rb +5 -2
- data/lib/phony/countries/uruguay.rb +2 -0
- data/lib/phony/countries/vietnam.rb +94 -92
- data/lib/phony/countries/zimbabwe.rb +2 -0
- data/lib/phony/countries.rb +210 -98
- data/lib/phony/country.rb +15 -3
- data/lib/phony/country_codes.rb +17 -4
- data/lib/phony/dsl.rb +5 -3
- data/lib/phony/local_splitters/fixed.rb +2 -0
- data/lib/phony/national_code.rb +1 -1
- data/lib/phony/national_splitters/none.rb +1 -3
- data/lib/phony/trunk_code.rb +5 -4
- data/lib/phony/vanity.rb +1 -1
- data/lib/phony.rb +94 -59
- data/spec/functional/config_spec.rb +44 -0
- data/spec/functional/plausibility_spec.rb +373 -35
- data/spec/lib/phony/countries_spec.rb +295 -63
- data/spec/lib/phony/country_codes_spec.rb +106 -33
- data/spec/lib/phony/country_spec.rb +54 -15
- data/spec/lib/phony/dsl_spec.rb +2 -2
- data/spec/lib/phony/local_splitters/regex_spec.rb +12 -5
- data/spec/lib/phony/national_splitters/default_spec.rb +1 -1
- data/spec/lib/phony/trunk_code_spec.rb +85 -0
- data/spec/lib/phony/vanity_spec.rb +30 -0
- data/spec/lib/phony_spec.rb +70 -0
- metadata +27 -17
data/lib/phony/countries.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
# All countries, ordered by country code.
|
3
5
|
#
|
4
6
|
# Definitions are in the format:
|
@@ -67,7 +69,7 @@ Phony.define do
|
|
67
69
|
country '20', one_of('800') >> split(7..7) | # Egypt toll free
|
68
70
|
one_of('3') >> split(7..7) | # Alexandria
|
69
71
|
one_of('2') >> split(8..8) | # Cairo/Giza
|
70
|
-
one_of('10', '11', '12') >> split(8..8) | # the
|
72
|
+
one_of('10', '11', '12', '15') >> split(8..8) | # the 4 mobile operators
|
71
73
|
fixed(2) >> split(7..7) # all the other 24 provinces
|
72
74
|
|
73
75
|
# South Africa.
|
@@ -94,13 +96,16 @@ Phony.define do
|
|
94
96
|
# Belgium.
|
95
97
|
#
|
96
98
|
# http://en.wikipedia.org/wiki/Telephone_numbers_in_Belgium
|
99
|
+
# https://www.bipt.be/operators/publication/national-numbering-plan
|
97
100
|
#
|
98
101
|
country '32', trunk('0') |
|
99
|
-
match(/^(
|
100
|
-
match(/^(
|
101
|
-
match(/^(
|
102
|
-
|
103
|
-
|
102
|
+
match(/^(7[08])\d+$/) >> split(3,3) | # Premium and national rate Services
|
103
|
+
match(/^(800|90\d)\d+$/) >> split(2,3) | # Toll free service and premium numbers
|
104
|
+
match(/^(46[056789])\d{6}$/) >> split(2,2,2) | # Mobile (Lycamobile, Telenet, Join Experience, Proximus 0460)
|
105
|
+
match(/^(4[789]\d)\d{6}$/) >> split(2,2,2) | # Mobile
|
106
|
+
match(/^(45[56])\d{6}$/) >> split(2,2,2) | # Mobile Vikings and Voo
|
107
|
+
one_of('2','3','4','9') >> split(3,2,2) | # Short NDCs
|
108
|
+
fixed(2) >> split(2,2,2) # 2-digit NDCs
|
104
109
|
|
105
110
|
# France.
|
106
111
|
#
|
@@ -121,11 +126,19 @@ Phony.define do
|
|
121
126
|
|
122
127
|
# Hungary.
|
123
128
|
#
|
129
|
+
# http://webpub-ext.nmhh.hu/aga/foldr/DoIndexAction.do
|
130
|
+
#
|
124
131
|
country '36',
|
125
132
|
trunk('06', normalize: false) |
|
126
|
-
one_of('104','105','107','112')
|
127
|
-
one_of('1')
|
128
|
-
|
133
|
+
one_of('104', '105', '107', '112') >> split(3,3) | # Service
|
134
|
+
one_of('1') >> split(3,4) | # Budapest
|
135
|
+
one_of('20', '30', '31', '50', '70') >> split(3,4) | # Mobile
|
136
|
+
one_of('21') >> split(3,4) | # VOIP
|
137
|
+
one_of('40', '80', '90', '91') >> split(3,3) | # Special charged numbers
|
138
|
+
one_of('51') >> split(3,3) | # Corporate network, M2M
|
139
|
+
one_of('38') >> split(3,4) | # Corporate network, M2M
|
140
|
+
one_of('71') >> split(5,5) | # M2M Numbers
|
141
|
+
fixed(2) >> split(3,3) # Geographic numbers
|
129
142
|
|
130
143
|
# country '39' # Italy, see special file.
|
131
144
|
|
@@ -136,13 +149,15 @@ Phony.define do
|
|
136
149
|
match(/^(112|800|90[036])\d+$/) >> split(3,3) | # Service
|
137
150
|
match(/^(7[1-9])\d+$/) >> split(3,4) | # Mobile
|
138
151
|
one_of('21', '31') >> split(3,4) | # Bucureşti
|
139
|
-
fixed(3) >> split(3,
|
152
|
+
fixed(3) >> split(3,3) # 3-digit NDCs
|
140
153
|
|
141
154
|
# Switzerland.
|
142
155
|
#
|
143
156
|
country '41',
|
144
157
|
trunk('0', normalize: true) |
|
145
|
-
match(/^(
|
158
|
+
match(/^(860)\d+$/) >> split(2, 3, 2, 2) | # Voice Mail access
|
159
|
+
match(/^(8(?:00|4[0248]))\d+$/) >> split(3,3) | # Freecall/Shared Cost
|
160
|
+
match(/^(90[016])\d+$/) >> split(3,3) | # Business
|
146
161
|
fixed(2) >> split(3,2,2)
|
147
162
|
|
148
163
|
# country '43' # Austria, see special file.
|
@@ -167,17 +182,19 @@ Phony.define do
|
|
167
182
|
# Note: http://wapedia.mobi/en/Telephone_numbers_in_Poland, mobile not yet correct
|
168
183
|
#
|
169
184
|
country '48',
|
170
|
-
match(/^(5[
|
185
|
+
match(/^(45\d|5[0137]\d|6[069]\d|7[02389]\d|80[01]|88\d)/) >> split(3,3) |
|
171
186
|
fixed(2) >> split(3,2,2)
|
172
187
|
|
173
188
|
# country '49' # Germany, see special file.
|
174
189
|
|
175
190
|
# Peru.
|
176
|
-
#
|
191
|
+
# Note: https://en.wikipedia.org/wiki/Telephone_numbers_in_Peru
|
192
|
+
# Note: https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=PE
|
177
193
|
country '51',
|
178
194
|
one_of('103', '105') >> split(3,3) | # Service.
|
179
|
-
one_of('
|
180
|
-
|
195
|
+
one_of('9') >> split(4,4) | # Mobile.
|
196
|
+
one_of('1') >> split(3,4) | # Lima.
|
197
|
+
fixed(2) >> split(3,3) # 2-digit NDCs.
|
181
198
|
|
182
199
|
# Mexico.
|
183
200
|
#
|
@@ -198,14 +215,7 @@ Phony.define do
|
|
198
215
|
fixed(3) >> split(7) # 3-digit NDCs
|
199
216
|
|
200
217
|
# Argentine Republic.
|
201
|
-
#
|
202
|
-
country '54',
|
203
|
-
one_of('11', '911') >> split(4,4) | # Fixed & Mobile
|
204
|
-
match(/^(22[0137]|237|26[14]|29[179]|34[1235]|35[138]|38[1578])/) >> split(3,4) | # Fixed
|
205
|
-
match(/^(922[0137]|9237|926[14]|929[179]|934[1235]|935[138]|938[1578])/) >> split(3,4) | # Mobile
|
206
|
-
match(/^(9\d{4})/) >> split(2,4) | # Mobile
|
207
|
-
match(/^([68]\d{2})/) >> split(3,4) | # Service
|
208
|
-
fixed(4) >> split(2,4) # Fixed
|
218
|
+
# country '54' # argentina, see special file.
|
209
219
|
|
210
220
|
# Brazil (Federative Republic of).
|
211
221
|
# http://en.wikipedia.org/wiki/Telephone_numbers_in_Brazil
|
@@ -222,6 +232,7 @@ Phony.define do
|
|
222
232
|
# http://www.itu.int/oth/T020200002C/en
|
223
233
|
country '57',
|
224
234
|
match(/\A(3\d\d)\d+\z/) >> split(3,4) | # mobile (300 310 311 312 313 315 316)
|
235
|
+
match(/\A(60\d)\d+\z/) >> split(3,4) |
|
225
236
|
fixed(1) >> split(3,4)
|
226
237
|
|
227
238
|
# Venezuela (Bolivarian Republic of)
|
@@ -234,8 +245,11 @@ Phony.define do
|
|
234
245
|
# Australia.
|
235
246
|
#
|
236
247
|
country '61',
|
237
|
-
trunk('0') |
|
248
|
+
trunk('0', format: false) |
|
238
249
|
match(/^(4\d\d)\d+$/) >> split(3,3) | # Mobile
|
250
|
+
match(/^(1800)\d+$/) >> split(3,3) | # 1800 free call
|
251
|
+
match(/^(1300)\d+$/) >> split(3,3) | # 1300 local rate
|
252
|
+
match(/^(13)\d+$/) >> split(2,2) | # 13 local rate
|
239
253
|
fixed(1) >> split(4,4) # Rest
|
240
254
|
|
241
255
|
# country '62' # Indonesia (Republic of), see special file
|
@@ -246,9 +260,10 @@ Phony.define do
|
|
246
260
|
trunk('0') |
|
247
261
|
# 7/10 digits for area code '2'.
|
248
262
|
match(/\A(2)\d{10}\z/) >> split(10) |
|
263
|
+
match(/\A(2)\d{8}\z/) >> split(8) |
|
249
264
|
one_of('2') >> split(7) |
|
250
265
|
# mobile
|
251
|
-
match(/\A(
|
266
|
+
match(/\A([89]\d\d)\d{7}\z/) >> split(7) |
|
252
267
|
match(/\A(9\d\d)\d+\z/) >> split(6) |
|
253
268
|
#
|
254
269
|
fixed(2) >> split(7)
|
@@ -260,18 +275,23 @@ Phony.define do
|
|
260
275
|
match(/^(2\d)\d{7}$/) >> split(3,4) | # Mobile
|
261
276
|
match(/^(2\d)\d{6}$/) >> split(3,3) |
|
262
277
|
match(/^(2\d)\d{8}$/) >> split(2,3,3) |
|
278
|
+
match(/^(800)\d{6}$/) >> split(3,3) | # International 800 service where agreed
|
279
|
+
match(/^(800)\d{7}$/) >> split(3,4) | # International 800 service where agreed
|
263
280
|
fixed(1) >> split(3,4) # Rest
|
264
281
|
|
265
282
|
# Singapore (Republic of).
|
266
283
|
#
|
267
284
|
country '65',
|
268
|
-
none >>
|
285
|
+
none >> matched_split(
|
286
|
+
/^(800)\d{7}$/ => [3,3,4], # International Toll Free Service (ITFS) and Home Country Direct Service (HCDS) Numbers
|
287
|
+
/^\d{8}$/ => [4,4] # TODO Short Codes
|
288
|
+
)
|
269
289
|
|
270
290
|
# Thailand.
|
271
291
|
#
|
272
292
|
country '66',
|
273
293
|
trunk('0') |
|
274
|
-
match(/\A([
|
294
|
+
match(/\A([689]\d\d)\d+\z/) >> split(3,3) | # mobile
|
275
295
|
one_of('2') >> split(3,4) | # Bangkok
|
276
296
|
fixed(2) >> split(3,3) # Rest
|
277
297
|
|
@@ -335,20 +355,20 @@ Phony.define do
|
|
335
355
|
|
336
356
|
# Côte d'Ivoire
|
337
357
|
# http://www.wtng.info/wtng-225-ci.html
|
338
|
-
#
|
358
|
+
# https://www.itu.int/dms_pub/itu-t/oth/02/02/T02020000310006PDFE.pdf
|
339
359
|
# http://en.wikipedia.org/wiki/Telephone_numbers_in_Ivory_Coast
|
340
360
|
#
|
341
361
|
# There is no trunk code for this country and several of the mobile prefixes start with 0
|
342
362
|
country '225',
|
343
363
|
trunk('', :normalize => false) |
|
344
|
-
fixed(2) >> split(2,2,2)
|
364
|
+
fixed(2) >> split(2,2,2,2)
|
345
365
|
|
346
366
|
country '226', none >> split(4,4) # Burkina Faso http://www.wtng.info/wtng-226-bf.html
|
347
367
|
country '227', none >> split(4,4) # Niger http://www.wtng.info/wtng-227-ne.html
|
348
368
|
country '228', none >> split(4,4) # Togolese Republic http://www.wtng.info/wtng-228-tg.html
|
349
369
|
country '229', none >> split(4,4) # Benin http://www.itu.int/oth/T0202000017/en
|
350
370
|
|
351
|
-
country '230', none >> split(
|
371
|
+
country '230', none >> split(4,4) # Mauritius http://www.wtng.info/wtng-230-mu.html
|
352
372
|
|
353
373
|
# Liberia
|
354
374
|
# https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=LR
|
@@ -366,32 +386,43 @@ Phony.define do
|
|
366
386
|
# Ghana
|
367
387
|
#
|
368
388
|
# From http://www.itu.int/oth/T0202000052/en
|
389
|
+
# https://en.wikipedia.org/wiki/Telephone_numbers_in_Ghana
|
369
390
|
#
|
370
|
-
country '233', fixed(2) >> split(3,4)
|
391
|
+
country '233', trunk('0') | fixed(2) >> split(3,4)
|
371
392
|
|
372
393
|
# Nigeria
|
373
|
-
#
|
394
|
+
# 3 4 split for mobile and 1 digit NDC, 3 2 or 3 3 otherwise
|
395
|
+
# Many local numbers with no splitting
|
374
396
|
#
|
375
|
-
# mobile telephony number allocation taken from:
|
397
|
+
# mobile telephony number allocation taken from:
|
398
|
+
# https://www.ncc.gov.ng/technical-regulation/standards/numbering and
|
399
|
+
# https://www.itu.int/oth/T020200009C/en
|
376
400
|
country '234',
|
377
|
-
match(/^([7-9]0\d)\d+$/)
|
378
|
-
match(/^(81\d)\d+$/)
|
379
|
-
|
380
|
-
|
401
|
+
match(/^([7-9]0\d)\d+$/) >> split(3,4) | # Mobile
|
402
|
+
match(/^(81\d)\d+$/) >> split(3,4) | # Mobile
|
403
|
+
match(/^(91\d)\d+$/) >> split(3,4) | # Mobile
|
404
|
+
one_of('1', '2') >> split(3,3..4) | # Lagos, Ibadan
|
405
|
+
one_of('9') >> split(3,4) | # Abuja
|
406
|
+
one_of((30..79).map(&:to_s)) >> split(3,2..3) | # 2-digit NDC
|
407
|
+
one_of(%w(82 83 84 85 86 87 88 89)) >> split(3,3) # 2-digit NDC
|
381
408
|
|
382
409
|
country '235', none >> split(4,4) # Chad http://www.wtng.info/wtng-235-td.html
|
383
410
|
country '236', none >> split(4,4) # Central African Republic http://www.wtng.info/wtng-236-cf.html
|
384
|
-
country '237', none >> split(
|
411
|
+
country '237', none >> split(3,2,2,2) # Cameroon http://www.wtng.info/wtng-237-cm.html
|
385
412
|
country '238', none >> split(3,4) # Cape Verde http://www.wtng.info/wtng-238-cv.html
|
386
413
|
country '239', fixed(1) >> split(3,3) # Sao Tome and Principe, http://www.wtng.info/wtng-239-st.html
|
387
414
|
|
388
415
|
country '240', none >> split(3,3,3) # Equatorial Guinea
|
389
|
-
country '241',
|
390
|
-
|
391
|
-
|
416
|
+
country '241',
|
417
|
+
match(/^(\d)\d{6}$/) >> split(3,3) | # Gabonese Republic http://www.wtng.info/wtng-241-ga.html
|
418
|
+
match(/^(\d\d)\d{6}$/) >> split(2,2,2) # 2019 update https://en.wikipedia.org/wiki/Telephone_numbers_in_Gabon
|
419
|
+
country '242', # Congo http://www.wtng.info/wtng-242-cg.html
|
420
|
+
trunk('', :normalize => false) |
|
421
|
+
none >> split(4,5)
|
422
|
+
country '243', fixed(2) >> split(3,4) # Democratic Republic of the Congo http://www.wtng.info/wtng-243-cd.html
|
392
423
|
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
|
393
424
|
fixed(2) >> split(3,4)
|
394
|
-
country '245', none >> split(3,4) # Guinea-Bissau http://www.wtng.info/wtng-245-gw.html
|
425
|
+
country '245', none >> split(2,3,4) # Guinea-Bissau http://www.wtng.info/wtng-245-gw.html
|
395
426
|
country '246', none >> split(3,4) # Diego Garcia http://www.wtng.info/wtng-246-io.html
|
396
427
|
country '247', none >> split(4) # Ascension
|
397
428
|
|
@@ -404,9 +435,9 @@ Phony.define do
|
|
404
435
|
# http://en.wikipedia.org/wiki/Telephone_numbers_in_Rwanda
|
405
436
|
country '250',
|
406
437
|
trunk('0') |
|
407
|
-
one_of('25')
|
408
|
-
match(/^(7[
|
409
|
-
one_of('06')
|
438
|
+
one_of('25') >> split(7) | # Geographic, fixed
|
439
|
+
match(/^(7[2389])/) >> split(7) | # Non-geographic, mobile
|
440
|
+
one_of('06') >> split(6) # Satellite
|
410
441
|
|
411
442
|
country '251', fixed(2) >> split(3, 4) # Ethiopia http://www.wtng.info/wtng-251-et.html
|
412
443
|
|
@@ -456,25 +487,33 @@ Phony.define do
|
|
456
487
|
|
457
488
|
# Zambia
|
458
489
|
# http://www.wtng.info/wtng-260-zm.html
|
490
|
+
# https://github.com/googlei18n/libphonenumber/
|
491
|
+
# https://en.wikipedia.org/wiki/Telephone_numbers_in_Zambia
|
492
|
+
|
459
493
|
country '260',
|
460
|
-
|
461
|
-
match(/^(
|
494
|
+
trunk('0') |
|
495
|
+
match(/^(75|76|77|94|95|96|97)/) >> split(3, 4) | # Mobile
|
496
|
+
match(/^(800)/) >> split(3,3) | # Toll free
|
497
|
+
match(/^(21[1-8])/) >> split(6) # Fixed
|
462
498
|
|
463
|
-
# Madagascar
|
499
|
+
# Madagascar
|
500
|
+
# https://en.wikipedia.org/wiki/Telephone_numbers_in_Madagascar
|
464
501
|
# http://www.itu.int/oth/T020200007F/en
|
465
502
|
country '261',
|
466
|
-
none >> matched_split(
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
)
|
503
|
+
# none >> matched_split(
|
504
|
+
# /\A20\d+\z/ => [2,2,3,2], # Telecom Malagasy (Telma)
|
505
|
+
# /\A32\d+\z/ => [2,2,3,2], # mobile Orange Madagascar
|
506
|
+
# /\A33\d+\z/ => [2,2,3,2], # mobile Airtel Madagascar
|
507
|
+
# /\A34\d+\z/ => [2,2,3,2], # mobile Telecom Malagasy (Telma)
|
508
|
+
# /\A38\d+\z/ => [2,2,3,2], # mobile Telecom Malagasy (Telma)
|
509
|
+
# /\A39\d+\z => [2,2,3,2] # mobile Blueline
|
510
|
+
# ),
|
511
|
+
match(/\A(20)\d+\z/) >> split(2,3,2) | # fix Telecom Malagasy (Telma)
|
512
|
+
match(/\A(32)\d+\z/) >> split(2,3,2) | # mobile Orange Madagascar
|
513
|
+
match(/\A(33)\d+\z/) >> split(2,3,2) | # mobile Airtel Madagascar
|
514
|
+
match(/\A(34)\d+\z/) >> split(2,3,2) | # mobile Telecom Malagasy (Telma)
|
515
|
+
match(/\A(38)\d+\z/) >> split(2,3,2) | # mobile Telecom Malagasy (Telma)
|
516
|
+
match(/\A(39)\d+\z/) >> split(2,3,2) # mobile Blueline Madagascar
|
478
517
|
|
479
518
|
country '262', # Reunion / Mayotte (new) http://www.wtng.info/wtng-262-fr.html
|
480
519
|
trunk('0') |
|
@@ -595,17 +634,26 @@ Phony.define do
|
|
595
634
|
# Luxembourg
|
596
635
|
#
|
597
636
|
country '352',
|
598
|
-
|
599
|
-
match(/^(
|
600
|
-
match(/^(
|
601
|
-
match(/^(
|
602
|
-
match(/^([
|
637
|
+
match(/^(2[467]\d{2})\d{4}$/) >> split(2,2) | # 4-digit NDC
|
638
|
+
match(/^(6\d[18])\d+$/) >> split(3,3) | # mobile
|
639
|
+
match(/^(60\d{2})\d{8}$/) >> split(2,2,2,2) | # mobile machine to machine
|
640
|
+
match(/^((2[^467]|[3-9]\d))\d{4}$/) >> split(2,2) | # 2-digit NDC Regular 6 digits number
|
641
|
+
match(/^((2[^467]|[3-9]\d))\d{4}$/) >> split(2,2) | # 2-digit NDC Regular 6 digits number
|
642
|
+
match(/^((2[^467]|[3-9]\d))\d{5}$/) >> split(2,2,1) | # 2-digit NDC Regular 6 digits number w/ 1 digit extension
|
643
|
+
match(/^((2[^467]|[3-9]\d))\d{6}$/) >> split(2,2,2) | # 2-digit NDC Regular 8 digits number or 6 digits with 2 digits extension
|
644
|
+
match(/^((2[^467]|[3-9]\d))\d{7}$/) >> split(2,2,3) | # 2-digit NDC Regular 6 digits with 4 digits extension
|
645
|
+
match(/^((2[^467]|[3-9]\d))\d{8}$/) >> split(2,2,4) | # 2-digit NDC Regular 6 digits number with 4 digits extension
|
646
|
+
match(/^(\d{2})\d{3}$/) >> split(2,2,1) # fallback for 5 digit number
|
603
647
|
|
604
648
|
# country '353' # Republic of Ireland, see special file.
|
605
649
|
|
606
650
|
country '354', none >> split(3,4) # Iceland
|
651
|
+
|
652
|
+
# Albania
|
653
|
+
# https://en.wikipedia.org/wiki/Telephone_numbers_in_Albania
|
607
654
|
country '355', trunk('0') |
|
608
|
-
one_of('4') >> split(4
|
655
|
+
one_of('4') >> split(3,4) | # Tirana
|
656
|
+
match(/\A(6[6-9])\d*\z/) >> split(3,4) | # mobile
|
609
657
|
match(/\A(2[24]|3[2-5]|47|5[2-5]|6[6-9]|8[2-5])\d*\z/) >> split(3,3) |
|
610
658
|
fixed(3) >> split(3,2)
|
611
659
|
|
@@ -626,17 +674,48 @@ Phony.define do
|
|
626
674
|
#
|
627
675
|
country '358',
|
628
676
|
trunk('0') |
|
629
|
-
match(/^([
|
630
|
-
match(/^([
|
631
|
-
match(/^(4\d
|
632
|
-
|
633
|
-
|
677
|
+
match(/^(600[3-5]\d|601\d\d|700[3457]\d|7500[12]|7532[12]|7575[12]|7598[12])\d{3,4}$/) >> split(3..4) | # national service numbers, 5-digit NDC
|
678
|
+
match(/^(753[02][3-9]|7575[3-9]|7598[3-9])\d{3,5}$/) >> split(3..5) | # national subscriber numbers, 5-digit NDC
|
679
|
+
match(/^(73[0-4]\d\d)\d{5}$/) >> split(5) | # national subscriber numbers, 5-digit NDC (starting with 073)
|
680
|
+
match(/^(202[023]|209[8-9]|600[0126-9]|700[0126]|7099|800\d)\d{4,5}$/) >> split(2, 2..3) | # national service numbers, 4-digit NDCs
|
681
|
+
match(/^(606\d|70[78]\d)\d{6}$/) >> split(3, 3) | # national service numbers, 4-digit NDCs (starting with 0606/0707/0708)
|
682
|
+
match(/^(202[14-9]|209[0-7])\d{4,6}$/) >> split(3, 1..3) | # national subscriber numbers, 4-digit NDCs
|
683
|
+
match(/^(45[45789]\d)\d{2,6}$/) >> split(2, 0..4) | # mobile numbers, 4-digit NDCs
|
684
|
+
match(/^([123]00|602)\d{5,6}$/) >> split(3, 2..3) | # national service numbers, 3-digit NDCs
|
685
|
+
match(/^(10[1-9]|20[13-8]|30[1-9]|73[5-9])\d{5,7}$/) >> split(3, 2..4) | # national subscriber numbers, 3-digit NDCs
|
686
|
+
match(/^(71\d)\d{6}$/) >> split(3, 3) | # national subscriber numbers, 3-digit NDCs (starting with 071)
|
687
|
+
match(/^(73[5-9])\d{7}$/) >> split(3, 4) | # national subscriber numbers, 3-digit NDCs (starting with 073)
|
688
|
+
match(/^(43\d|45[0-36])\d{5,7}$/) >> split(3, 2..4) | # mobile numbers, 3-digit NDCs
|
689
|
+
match(/^(49\d)\d{8}$/) >> split(3, 3, 2) | # mobile numbers, 3-digit NDCs (starting with 049)
|
690
|
+
match(/^([235]9)\d{6,8}$/) >> split(3, 3, 0..2) | # national subscriber numbers, 2-digit NDCs
|
691
|
+
match(/^(4[0124678]|50)\d{4,8}$/) >> split(3, 1..5) | # mobile numbers, 2-digit NDCs
|
692
|
+
one_of('2','3','5','6','8','9') >> split(3,1..5) | # Short NDCs
|
693
|
+
fixed(2) >> split(3, 0..4) # 2-digit NDCs
|
634
694
|
|
635
695
|
# Bulgaria
|
636
696
|
#
|
697
|
+
# Note: https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=BG
|
698
|
+
# Note: https://en.wikipedia.org/wiki/Telephone_numbers_in_Bulgaria
|
637
699
|
country '359',
|
638
700
|
trunk('0') |
|
639
|
-
|
701
|
+
match(/^(2)\d{6}$/) >> split(3,3) | # Landline Sofia (optional last digit)
|
702
|
+
match(/^(2)\d{7}$/) >> split(3,4) | # Landline Sofia (optional last digit)
|
703
|
+
match(/^(30|31|33|36|37|39|41|43\d|45|47|51|53|55|57|59)\d{5}$/) >> split(5) |
|
704
|
+
match(/^(30|31|32|33|34|35|36|37|38|39|41|42|44|45|46|47|51|52|53|54|55|56|57|58|59)\d{6}$/) >> split(2,4) |
|
705
|
+
|
706
|
+
match(/^(60|61|63|65|66|69)\d{5}$/) >> split(5) |
|
707
|
+
match(/^(60|61|62|63|64|65|66|68|69)\d{6}$/) >> split(6) |
|
708
|
+
|
709
|
+
match(/^(700|701|703|704|705|706|707|708|709)\d{5}$/) >> split(5) |
|
710
|
+
match(/^(701|702|703|704|705|706|707|708|709)\d{4}$/) >> split(4) |
|
711
|
+
|
712
|
+
match(/^(71|72|74|75|77)\d{5}$/) >> split(5) |
|
713
|
+
match(/^(71|72|73|74|75|76|77|78|79)\d{6}$/) >> split(6) |
|
714
|
+
|
715
|
+
match(/^(80\d|81|91|93|95|97)\d{5}$/) >> split(5) |
|
716
|
+
match(/^(81|82|84|86)\d{6}$/) >> split(6) |
|
717
|
+
match(/^(87|88|89)\d{7}$/) >> split(4,3) |
|
718
|
+
match(/^(90|91|92|93|94|95|96|97|98\d|99\d)\d{6}$/) >> split(6)
|
640
719
|
|
641
720
|
# Lithuania
|
642
721
|
#
|
@@ -670,11 +749,12 @@ Phony.define do
|
|
670
749
|
# Monaco
|
671
750
|
#
|
672
751
|
country '377',
|
673
|
-
one_of('6')
|
752
|
+
one_of('6') >> split(2,2,2,2) | # mobile
|
674
753
|
fixed(2) >> split(2,2,2)
|
675
754
|
|
676
755
|
# San Marino
|
677
756
|
country '378',
|
757
|
+
trunk('', :normalize => false) |
|
678
758
|
none >> matched_split(
|
679
759
|
/\A\d{6}\z/ => [3,3],
|
680
760
|
/\A\d+\z/ => [3,3,4]
|
@@ -688,7 +768,13 @@ Phony.define do
|
|
688
768
|
|
689
769
|
# country '382' # Montenegro, see special file
|
690
770
|
|
691
|
-
|
771
|
+
# Kosovo
|
772
|
+
#
|
773
|
+
# Note: https://en.wikipedia.org/wiki/Telephone_numbers_in_Kosovo
|
774
|
+
country '383',
|
775
|
+
trunk('0') |
|
776
|
+
fixed(2) >> split(3,3)
|
777
|
+
|
692
778
|
country '384', todo # -
|
693
779
|
|
694
780
|
# country '385' # Croatia, see special file.
|
@@ -702,17 +788,23 @@ Phony.define do
|
|
702
788
|
one_of('1','2','3','4','5','7') >> split(3,4) | # Ljubljana, Maribor, Celje, Kranj, Nova Gorica, Novo mesto
|
703
789
|
fixed(3) >> split(2,3) # catchall
|
704
790
|
|
705
|
-
country '387', trunk('0') | fixed(2) >> split(3,
|
791
|
+
country '387', trunk('0') | fixed(2) >> split(3,3) # Bosnia and Herzegovina
|
706
792
|
country '388', trunk('0') | fixed(2) >> split(3,2,2) # Group of countries, shared code
|
707
|
-
|
793
|
+
|
794
|
+
# The Former Yugoslav Republic of Macedonia
|
795
|
+
country '389',
|
796
|
+
trunk('0') |
|
797
|
+
one_of('2','3','4','5','6','7','8') >> split(3,4)
|
708
798
|
|
709
799
|
country '420', fixed(3) >> split(3,3) # Czech Republic
|
710
800
|
|
711
801
|
# Slovak Republic.
|
712
802
|
#
|
713
|
-
country '421', match(/^(9\d\d).+$/)
|
714
|
-
|
715
|
-
|
803
|
+
country '421', match(/^(9\d\d).+$/) >> split(6) | # Mobile
|
804
|
+
match(/\A(2)1\d{2,4}\z/) >> split(3..5) | # Bratislava Short
|
805
|
+
match(/\A(\d{2})1\d{2,4}\z/) >> split(3..5) | # 2-digit NDCs Short
|
806
|
+
one_of('2') >> split(8) | # Bratislava
|
807
|
+
fixed(2) >> split(7) # 2-digit NDCs
|
716
808
|
|
717
809
|
country '422', todo # Spare code
|
718
810
|
country '423', none >> split(3,2,2) # Liechtenstein (Principality of)
|
@@ -784,7 +876,14 @@ Phony.define do
|
|
784
876
|
one_of(%w(11 16 17 18 19)) >> split(3) | # audiotext
|
785
877
|
fixed(3) >> split(4) # geographic, audiotext
|
786
878
|
|
787
|
-
|
879
|
+
# Ecuador http://www.wtng.info/wtng-593-ec.html
|
880
|
+
# https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=EC¤t_page=1
|
881
|
+
# https://en.wikipedia.org/wiki/Telephone_numbers_in_Ecuador
|
882
|
+
country '593',
|
883
|
+
one_of('9') >> split(4,4) |
|
884
|
+
match(/\A([\d]{2})\d{7}\z/) >> split(3,4) |
|
885
|
+
fixed(1) >> split(3,4)
|
886
|
+
|
788
887
|
country '594', fixed(3) >> split(3, 3) # French Guiana (French Department of) http://www.wtng.info/wtng-594-fr.html
|
789
888
|
|
790
889
|
# country '595' # Paraguay (Republic of), see special file
|
@@ -830,7 +929,14 @@ Phony.define do
|
|
830
929
|
one_of('115') >> split(4,4) | # voicemail (mobile)
|
831
930
|
one_of(%w(28 29)) >> split(3,2) | # pager
|
832
931
|
one_of(%w(16 18)) >> split(3,2) | # ISP
|
833
|
-
one_of(%w(71 72
|
932
|
+
one_of(%w(70 71 72 74 75 76 78 79)) >> split(3,3) | # mobile
|
933
|
+
one_of(%w(731 732 733 734 735 736 738 739)) >> split(2,3) | # mobile
|
934
|
+
one_of(%w(770)) >> split(2,3) | # wireless geographic; Port Moresby, National Capital District
|
935
|
+
one_of(%w(771)) >> split(2,3) | # wireless geographic; Momase region
|
936
|
+
one_of(%w(772)) >> split(2,3) | # wireless geographic; Highlands region
|
937
|
+
one_of(%w(7730)) >> split(1,3) | # wireless geographic; Southern region
|
938
|
+
one_of(%w(774)) >> split(2,3) | # wireless geographic; Islands region
|
939
|
+
one_of(%w(775)) >> split(2,3) | # mobile
|
834
940
|
one_of(%w(80 81 82 83)) >> split(3,3) | # freephone
|
835
941
|
one_of(%w(90 91 92 93)) >> split(3,3) | # geographic, ISDN
|
836
942
|
one_of(%w(3 4 5 6 7 8 9)) >> split(3,3) # geographic
|
@@ -873,7 +979,7 @@ Phony.define do
|
|
873
979
|
/\A800\d+\z/ => [3,3], # freephone
|
874
980
|
/\A830\d+\z/ => [3,3], # shared cost
|
875
981
|
/\A60\d+\z/ => [3,3], # wireless geographic
|
876
|
-
/\A(72|75|76|77)\d+\z/ => [3,4], # mobile
|
982
|
+
/\A(71|72|75|76|77)\d+\z/ => [3,4], # mobile
|
877
983
|
/\A84\d+\z/ => [3,4], # wireless geographic
|
878
984
|
/\A\d+\z/ => [2,3] # geographic
|
879
985
|
)
|
@@ -894,7 +1000,10 @@ Phony.define do
|
|
894
1000
|
country '698', todo # -
|
895
1001
|
country '699', todo # -
|
896
1002
|
|
897
|
-
|
1003
|
+
# International Freephone Service
|
1004
|
+
# https://www.itu.int/en/ITU-T/inr/unum/Pages/uifn.aspx
|
1005
|
+
country '800', none >> split(8)
|
1006
|
+
|
898
1007
|
country '801', todo # -
|
899
1008
|
country '802', todo # -
|
900
1009
|
country '803', todo # -
|
@@ -902,7 +1011,7 @@ Phony.define do
|
|
902
1011
|
country '805', todo # -
|
903
1012
|
country '806', todo # -
|
904
1013
|
country '807', todo # -
|
905
|
-
country '808',
|
1014
|
+
country '808', none >> split(12) # International Shared Cost Service (ISCS)
|
906
1015
|
country '809', todo # -
|
907
1016
|
|
908
1017
|
country '830', todo # -
|
@@ -933,9 +1042,15 @@ Phony.define do
|
|
933
1042
|
# Hong Kong, China
|
934
1043
|
|
935
1044
|
country '852',
|
1045
|
+
match(/^(800)\d+$/) >> split(2, 4) |
|
936
1046
|
none >> split(4,4)
|
937
1047
|
|
938
|
-
|
1048
|
+
# Macao, China
|
1049
|
+
country '853', # Macao, China
|
1050
|
+
match(/^(28)\d+$/) >> split(2,4) | # Landline.
|
1051
|
+
match(/^(8)\d+$/) >> split(3,4) | # Landline.
|
1052
|
+
match(/^(6)\d+$/) >> split(3,4) # Mobile.
|
1053
|
+
|
939
1054
|
country '854', todo # Spare code
|
940
1055
|
|
941
1056
|
# Lao People's Democratic Republic http://www.wtng.info/wtng-856-la.html, https://www.numberingplans.com
|
@@ -962,7 +1077,10 @@ Phony.define do
|
|
962
1077
|
# Bangladesh (People's Republic of)
|
963
1078
|
# country '880' # see special file
|
964
1079
|
|
965
|
-
|
1080
|
+
# Global Mobile Satellite System (i.e. Iridium, Globalstar, etc)
|
1081
|
+
# https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=QM
|
1082
|
+
country '881', fixed(1) >> split(3,5)
|
1083
|
+
|
966
1084
|
country '882', todo # International Networks, shared code
|
967
1085
|
country '883', todo # -
|
968
1086
|
country '884', todo # -
|
@@ -1041,14 +1159,7 @@ Phony.define do
|
|
1041
1159
|
/\A8\d+\z/ => [3,3], # geographic
|
1042
1160
|
)
|
1043
1161
|
|
1044
|
-
# Saudi Arabia (Kingdom of)
|
1045
|
-
# http://www.wtng.info/wtng-966-sa.html
|
1046
|
-
# http://www.citc.gov.sa/English/MediaCenter/awarenesscampaigns/Pages/PR_AWR_004.aspx
|
1047
|
-
# http://en.wikipedia.org/wiki/Telephone_numbers_in_Saudi_Arabia
|
1048
|
-
# https://answers.yahoo.com/question/index?qid=20090303142622AAQBoZ0
|
1049
|
-
country '966',
|
1050
|
-
match(/\A(5[0-9])\d+\z/) >> split(3,4) | # mobile numbers
|
1051
|
-
fixed(3) >> split(3,4)
|
1162
|
+
# country '966' # Saudi Arabia (Kingdom of), see special file.
|
1052
1163
|
|
1053
1164
|
# Yemen (Republic of)
|
1054
1165
|
# https://www.numberingplans.com/?page=dialling&sub=areacodes
|
@@ -1080,17 +1191,18 @@ Phony.define do
|
|
1080
1191
|
one_of(%w(500 700 900)) >> split(3,3) | # premium rate
|
1081
1192
|
one_of('800') >> matched_split(
|
1082
1193
|
/\A\d{2}\z/ => [2],
|
1194
|
+
/\A\d{7}\z/ => [2,3,2],
|
1083
1195
|
/\A\d+\z/ => [2,3,4]) | # freephone
|
1084
|
-
one_of(%w(50 52 55 56)) >> split(3,4) | # mobile
|
1196
|
+
one_of(%w(50 52 54 55 56 58)) >> split(3,4) | # mobile
|
1085
1197
|
one_of(%w(2 3 4 6 7 9)) >> split(3,4) |
|
1086
1198
|
fixed(1) >> split(3,4)
|
1087
1199
|
|
1088
1200
|
# Israel (State of) (also works for numbers in Palestinian territories)
|
1089
1201
|
country '972',
|
1090
1202
|
trunk('0') |
|
1091
|
-
one_of('1')
|
1092
|
-
one_of('2', '3', '4', '8', '9')
|
1093
|
-
match(/^(5[
|
1203
|
+
one_of('1') >> split(3,3,3) | # special numbers
|
1204
|
+
one_of('2', '3', '4', '8', '9') >> split(3,4) | # 1 digit ndc
|
1205
|
+
match(/^(5[012345689]|7[234679])\d+$/) >> split(3,4) # 2 digit ndc
|
1094
1206
|
|
1095
1207
|
country '973', none >> split(4,4..4) # Bahrain (Kingdom of) http://www.itu.int/oth/T0202000011/en
|
1096
1208
|
|
data/lib/phony/country.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Phony
|
2
4
|
|
3
5
|
#
|
@@ -95,6 +97,9 @@ module Phony
|
|
95
97
|
end
|
96
98
|
end
|
97
99
|
def format_cc_ndc trunk, ndc, local, type, space, parentheses, use_trunk
|
100
|
+
# Note: We mark NDCs that are of type "none" with false (nil trips plausible?). This would result in false being printed.
|
101
|
+
# Therefore we set NDC to nil when formatting.
|
102
|
+
ndc = nil if ndc == false
|
98
103
|
case type
|
99
104
|
when String
|
100
105
|
trunk &&= trunk.format(space, use_trunk)
|
@@ -123,6 +128,7 @@ module Phony
|
|
123
128
|
end
|
124
129
|
end
|
125
130
|
def format_ndc ndc, parentheses
|
131
|
+
ndc = nil if ndc == false # TODO
|
126
132
|
parentheses ? "(#{ndc})" : ndc
|
127
133
|
end
|
128
134
|
def format_with_ndc format, cc, ndc, local, space
|
@@ -154,10 +160,12 @@ module Phony
|
|
154
160
|
#
|
155
161
|
# In some cases it doesn't, like Italy.
|
156
162
|
#
|
157
|
-
|
163
|
+
# Note: Options such as CC
|
164
|
+
#
|
165
|
+
def normalize national_number, options = {}
|
158
166
|
clean! national_number
|
159
167
|
normalized = @codes.reduce national_number do |number, code|
|
160
|
-
result = code.normalize number
|
168
|
+
result = code.normalize number, options
|
161
169
|
break result if result
|
162
170
|
number
|
163
171
|
end
|
@@ -168,7 +176,7 @@ module Phony
|
|
168
176
|
#
|
169
177
|
def plausible? rest, hints = {}
|
170
178
|
local, _, ndc, *rest = internal_split rest
|
171
|
-
|
179
|
+
|
172
180
|
# Element based checking.
|
173
181
|
#
|
174
182
|
# Note: ndc == false means the country has none.
|
@@ -185,6 +193,10 @@ module Phony
|
|
185
193
|
#
|
186
194
|
ndc_needed = hints[:ndc]
|
187
195
|
return false if ndc_needed && !(ndc_needed === ndc)
|
196
|
+
|
197
|
+
# If there is no local part, we can assume it's not a plausible number.
|
198
|
+
# (Or, not defined correctly in Phony yet)
|
199
|
+
return false unless local
|
188
200
|
|
189
201
|
# Local code specific checks.
|
190
202
|
#
|