phony 2.18.10 → 2.19.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.textile +1 -1
- data/lib/phony/countries/cambodia.rb +1 -5
- data/lib/phony/countries/china.rb +5 -2
- data/lib/phony/countries/ireland.rb +6 -4
- data/lib/phony/countries/italy.rb +2 -1
- data/lib/phony/countries/japan.rb +7 -6
- data/lib/phony/countries/libya.rb +1 -1
- data/lib/phony/countries/serbia.rb +5 -1
- data/lib/phony/countries/taiwan.rb +1 -0
- data/lib/phony/countries/vietnam.rb +1 -0
- data/lib/phony/countries.rb +48 -34
- data/lib/phony/country.rb +8 -2
- data/lib/phony/country_codes.rb +2 -2
- data/lib/phony/dsl.rb +2 -2
- 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 -5
- data/spec/functional/plausibility_spec.rb +43 -11
- data/spec/lib/phony/countries_spec.rb +65 -10
- data/spec/lib/phony/country_codes_spec.rb +43 -45
- data/spec/lib/phony/country_spec.rb +13 -1
- data/spec/lib/phony/trunk_code_spec.rb +85 -0
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d971b51de8e8d0581c884f90238d00bbdeeee7ca248ae3b93ce75e5b759114fd
|
4
|
+
data.tar.gz: d37f03c8ca22a2fcf76b046a38cfd6cc6334d79cd377bb221e1610352b331ee7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '028169288dfdcd908210a144add1c6d6eb082703602fd4eaa069c9ca952fe8e3e8c0c46764244af569cf90ba5fb535681369b700e3f273bebde591c534e544d3'
|
7
|
+
data.tar.gz: dc281117fa228352a099b3dc28e77d13c7d8145ef93f50ab721817e6b0a6024a32e4f4587c191529142ba987498b62d9a1bd3b9c4cfbf3ae72f2537b70e375ab
|
data/README.textile
CHANGED
@@ -104,7 +104,7 @@ For example, when just loading the NANP CC, the retained memory usage is ~63kB.
|
|
104
104
|
|
105
105
|
h2. List of Handled Countries
|
106
106
|
|
107
|
-
Mildly unmaintained list: Abhas, Afghan, Algerian, Argentina, 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, Liberian, 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, Vietnamese, and Zambian numbers.
|
107
|
+
Mildly unmaintained list: Abhas, Afghan, Algerian, Argentina, 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, Japanese, Kazakh, Liberian, 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, Vietnamese, and Zambian numbers.
|
108
108
|
|
109
109
|
h2. License
|
110
110
|
|
@@ -71,6 +71,7 @@ six_digit_extended_range_mobile_prefixes = [
|
|
71
71
|
]
|
72
72
|
|
73
73
|
seven_digit_mobile_prefixes = [
|
74
|
+
'18', # Seatel
|
74
75
|
'31', # Metfone
|
75
76
|
'38', # CooTel
|
76
77
|
'39', # EMAXX
|
@@ -85,10 +86,6 @@ variable_length_extended_range_mobile_prefixes = [
|
|
85
86
|
'12' # Mobitel
|
86
87
|
]
|
87
88
|
|
88
|
-
mobile_prefixes_with_variable_length = [
|
89
|
-
'18' # Seatel
|
90
|
-
]
|
91
|
-
|
92
89
|
six_digit_total_single_digit_fixed_line_prefixes = [
|
93
90
|
'2', # Telecom Cambodia
|
94
91
|
'3', # Mobitel
|
@@ -126,7 +123,6 @@ seven_digit_total_double_digit_fixed_line_prefixes = [
|
|
126
123
|
|
127
124
|
Phony.define do
|
128
125
|
country '855', trunk('0', :normalize => true) |
|
129
|
-
one_of(mobile_prefixes_with_variable_length) >> matched_split(/^9/ => [3, 4], /^[2-8]/ => [3, 3]) |
|
130
126
|
one_of(variable_length_extended_range_mobile_prefixes) >> matched_split(/^1/ => [3, 4], /^[2-9]/ => [3, 3]) |
|
131
127
|
one_of(six_digit_mobile_prefixes) >> matched_split(/^[2-9]/ => [3, 3]) |
|
132
128
|
one_of(six_digit_extended_range_mobile_prefixes) >> matched_split(/^[1-9]/ => [3, 3]) |
|
@@ -19,7 +19,7 @@ ndcs = [
|
|
19
19
|
'28', # Chengdu
|
20
20
|
'29', # Xi'an
|
21
21
|
]
|
22
|
-
mobile = %w{ 130 131 132 133 134 135 136 137 138 139 145 150 151 152 153 155 156 157 158 159 185 186 187 188 189 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 }
|
22
|
+
mobile = %w{ 130 131 132 133 134 135 136 137 138 139 145 146 147 148 149 150 151 152 153 155 156 157 158 159 162 165 166 167 170 171 172 173 174 175 176 177 178 180 181 182 183 184 185 186 187 188 189 190 191 192 193 195 196 197 198 199 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 }
|
23
23
|
service = %w{ 110 114 119 120 122 999 } # Probably not exhaustive. TODO Look at http://www.eoc.com.cn/?action-viewnews-itemid-11493.
|
24
24
|
|
25
25
|
Phony.define do
|
@@ -28,5 +28,8 @@ Phony.define do
|
|
28
28
|
one_of(service) >> split(8) |
|
29
29
|
one_of(mobile) >> split(4,4) |
|
30
30
|
one_of(ndcs) >> split(4,4) |
|
31
|
-
fixed(3) >>
|
31
|
+
fixed(3) >> matched_split(
|
32
|
+
/\A\d{7}\z/ => [3,4],
|
33
|
+
/\A\d{8}\z/ => [4,4]
|
34
|
+
)
|
32
35
|
end
|
@@ -9,14 +9,14 @@
|
|
9
9
|
#
|
10
10
|
# References:
|
11
11
|
# http://www.comreg.ie/_fileupload/publications/ComReg03147.pdf (2003)
|
12
|
+
# https://www.comreg.ie/media/dlm_uploads/2015/12/ComReg0804.pdf (2008)
|
12
13
|
# http://www.comreg.ie/licensing_and_services/area_code_maps.552.1040.html
|
13
14
|
# http://en.wikipedia.org/wiki/Telephone_numbers_in_the_Republic_of_Ireland
|
14
15
|
#
|
15
16
|
ndcs_with_5_subscriber_digits = [
|
16
|
-
'22', '
|
17
|
+
'22', '24', '25', '26', '27', '28', '29', # Mallow, Youghal, Fermoy, Macroom, Bantry, Skibbereen, Kanturk
|
17
18
|
'402', # Arklow
|
18
19
|
'404', # Wicklow
|
19
|
-
'43', # Longford, Granard
|
20
20
|
'47', # Monaghan, Clones
|
21
21
|
'48', # Northern Ireland
|
22
22
|
'502', # Portlaoise, Abbeyleix
|
@@ -24,12 +24,10 @@ ndcs_with_5_subscriber_digits = [
|
|
24
24
|
'505', # Roscrea
|
25
25
|
'506', # Tullamore
|
26
26
|
'509', # Bin-
|
27
|
-
'52', # Killenaule
|
28
27
|
'54', # Legacy Ferns, Enniscorthy
|
29
28
|
'55', # Legacy Gorey
|
30
29
|
'62', # Tipperary, Cashel
|
31
30
|
'63', # Charleville
|
32
|
-
'64', # Killarney, Rathmore
|
33
31
|
'67', # Nenagh
|
34
32
|
'68', # Listowel
|
35
33
|
'69', # Newcastle West
|
@@ -47,15 +45,19 @@ ndcs_with_6_subscriber_digits = [
|
|
47
45
|
ndcs_with_7_subscriber_digits = [
|
48
46
|
'1', # Dublin
|
49
47
|
'21', # Cork, Coachford, Kinsale
|
48
|
+
'23', # Bandon
|
50
49
|
'41', # Ardee
|
51
50
|
'42', # Dundalk, Carrickmacross, Castleblaney
|
51
|
+
'43', # Longford, Granard
|
52
52
|
'44', # Mullingar, Castlepollard, Tyrellspass
|
53
53
|
'46', # Navan, Kells, Trim, Enfield, Edenderry
|
54
54
|
'49', # Cavan, Cootehill, Oldcastle, Belturbet
|
55
|
+
'52', # Killenaule
|
55
56
|
'53', # Wexford, Enniscorthy, Ferns, Gorey, Craanford
|
56
57
|
'56', # Kilkenny, Castlecomer
|
57
58
|
'58', # Dungarvan
|
58
59
|
'59', # Carlow, Muine Bheag, Athy, Baltinglass
|
60
|
+
'64', # Killarney, Rathmore
|
59
61
|
'65', # Ennistymon, Kilrush
|
60
62
|
'66', # Tralee, Dingle, Killorglin, Cahirciveen
|
61
63
|
'71', # Sligo, Manorhamilton, Carrick-on-Shannon
|
@@ -269,7 +269,7 @@ service = [ # Not exhaustive.
|
|
269
269
|
]
|
270
270
|
|
271
271
|
Phony.define do
|
272
|
-
country '39', trunk('', :
|
272
|
+
country '39', trunk('', normalize: false) |
|
273
273
|
one_of(*service) >> split(3,3) |
|
274
274
|
one_of(*mobile) >> split(3,4,-1..1) |
|
275
275
|
one_of(*ndcs_2digit) >> split(4, 2..4) |
|
@@ -280,6 +280,7 @@ Phony.define do
|
|
280
280
|
/^[^1]\d{6}$/ => [7]
|
281
281
|
) |
|
282
282
|
one_of(*ndcs_4digit) >> matched_split(
|
283
|
+
/\A\d{4}\z/ => [4],
|
283
284
|
/^1\d{5}$/ => [6],
|
284
285
|
/^1\d{6}$/ => [7],
|
285
286
|
/^[^1]\d{4}$/ => [5],
|
@@ -166,6 +166,7 @@ ndcs_with_6_subscriber_numbers = %w(
|
|
166
166
|
422
|
167
167
|
428
|
168
168
|
436
|
169
|
+
438
|
169
170
|
439
|
170
171
|
460
|
171
172
|
463
|
@@ -281,7 +282,6 @@ ndcs_with_6_subscriber_numbers = %w(
|
|
281
282
|
846
|
282
283
|
847
|
283
284
|
848
|
284
|
-
849
|
285
285
|
852
|
286
286
|
853
|
287
287
|
854
|
@@ -361,7 +361,6 @@ ndcs_with_5_subscriber_numbers = %w(
|
|
361
361
|
1374
|
362
362
|
1377
|
363
363
|
1392
|
364
|
-
1394
|
365
364
|
1397
|
366
365
|
1398
|
367
366
|
1456
|
@@ -393,7 +392,6 @@ ndcs_with_5_subscriber_numbers = %w(
|
|
393
392
|
8477
|
394
393
|
8512
|
395
394
|
8514
|
396
|
-
8636
|
397
395
|
9496
|
398
396
|
9802
|
399
397
|
9912
|
@@ -403,12 +401,15 @@ ndcs_with_5_subscriber_numbers = %w(
|
|
403
401
|
|
404
402
|
Phony.define do
|
405
403
|
country '81',
|
406
|
-
trunk('0') |
|
407
|
-
one_of(
|
404
|
+
trunk('0', normalize: true, format: true, split: true) |
|
405
|
+
one_of(%w(20 50 60 70 90)) >> split(4,4) | # mobile, VoIP telephony
|
408
406
|
one_of(ndcs_with_5_subscriber_numbers) >> split(1,4) |
|
409
407
|
one_of(ndcs_with_6_subscriber_numbers) >> split(2,4) |
|
410
408
|
one_of(%w(120)) >> split(3,3) | # freephone
|
411
|
-
one_of(%w(
|
409
|
+
one_of(%w(800)) >> split(3,4) | # freephone
|
410
|
+
one_of(%w(180 570)) >> split(3,3) | # Tele-gong/Tele-dome, Navi-dial
|
411
|
+
one_of(%w(170 990)) >> split(2,4) | # Dengon-dial, Dial Q2 (discontinued)
|
412
|
+
one_of(%w(80)) >> split(4,4) | # mobile
|
412
413
|
one_of(ndcs_with_7_subscriber_numbers) >> split(3,4) |
|
413
414
|
one_of(ndcs_with_8_subscriber_numbers) >> split(4,4) |
|
414
415
|
# TODO: 91(NDC) N(S)N length: 5-13 - Non-geographic number (Direct subscriber telephone service (legacy))
|
@@ -111,6 +111,6 @@ Phony.define do
|
|
111
111
|
one_of(ndcs_with_5_subscriber_numbers) >> split(3,2) |
|
112
112
|
one_of(ndcs_with_6_subscriber_numbers) >> split(3,3) |
|
113
113
|
one_of(ndcs_with_7_subscriber_numbers) >> split(4,3) |
|
114
|
-
one_of(%w(91 92)) >> split(4,3) | # mobile
|
114
|
+
one_of(%w(91 92 94 95)) >> split(4,3) | # mobile
|
115
115
|
fixed(2) >> split(3,3)
|
116
116
|
end
|
@@ -8,6 +8,9 @@ Phony.define do
|
|
8
8
|
trunk('0') |
|
9
9
|
one_of(%w(800)) >> split(3,2) | # freephone
|
10
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]) |
|
11
14
|
one_of(%w(230)) >> matched_split(
|
12
15
|
/\A\d{4}\z/ => [4],
|
13
16
|
/\A\d+\z/ => [3,2]) |
|
@@ -21,6 +24,7 @@ Phony.define do
|
|
21
24
|
one_of(%w(72)) >> split(3,3) | # ISP
|
22
25
|
one_of(%w(60 61 68 69)) >> matched_split(
|
23
26
|
/\A\d{3}\z/ => [3],
|
27
|
+
/\A\d{6}\z/ => [3,3],
|
24
28
|
/\A\d{7}\z/ => [3,4],
|
25
29
|
/\A\d+\z/ => [3,3,4]) | # mobile, voicemail (mobile)
|
26
30
|
one_of(%w(66 63)) >> matched_split(
|
@@ -40,4 +44,4 @@ Phony.define do
|
|
40
44
|
fixed(2) >> matched_split(
|
41
45
|
/\A\d{5}\z/ => [3,2],
|
42
46
|
/\A\d+\z/ => [3,3])
|
43
|
-
end
|
47
|
+
end
|
@@ -11,6 +11,7 @@ Phony.define do
|
|
11
11
|
match(/\A(836)\d{5}\z/) >> split(1,4) | # 馬祖, start with 0836, plus 5 digits
|
12
12
|
match(/\A(82)\d{6}\z/) >> split(2,4) | # 金門, start with 082, plus 6 digits
|
13
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
|
14
15
|
match(/\A(8)\d{7}\z/) >> split(3,4) | # 屏東, start with 08, plus 7 digits
|
15
16
|
match(/\A(49)\d{7}\z/) >> split(3,4) | # 南投, start with 049, plus 7 digits
|
16
17
|
one_of(%w(4)) >> matched_split(
|
data/lib/phony/countries.rb
CHANGED
@@ -96,15 +96,16 @@ Phony.define do
|
|
96
96
|
# Belgium.
|
97
97
|
#
|
98
98
|
# http://en.wikipedia.org/wiki/Telephone_numbers_in_Belgium
|
99
|
+
# https://www.bipt.be/operators/publication/national-numbering-plan
|
99
100
|
#
|
100
101
|
country '32', trunk('0') |
|
101
|
-
match(/^(7[08])\d+$/)
|
102
|
-
match(/^(800|90\d)\d+$/)
|
103
|
-
match(/^(46[
|
104
|
-
match(/^(4[789]\d)\d{6}$/)
|
105
|
-
match(/^(
|
106
|
-
one_of('2','3','4','9')
|
107
|
-
fixed(2)
|
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
|
108
109
|
|
109
110
|
# France.
|
110
111
|
#
|
@@ -154,6 +155,7 @@ Phony.define do
|
|
154
155
|
#
|
155
156
|
country '41',
|
156
157
|
trunk('0', normalize: true) |
|
158
|
+
match(/^(860)\d+$/) >> split(2, 3, 2, 2) | # Voice Mail access
|
157
159
|
match(/^(8(?:00|4[0248]))\d+$/) >> split(3,3) | # Freecall/Shared Cost
|
158
160
|
match(/^(90[016])\d+$/) >> split(3,3) | # Business
|
159
161
|
fixed(2) >> split(3,2,2)
|
@@ -257,6 +259,7 @@ Phony.define do
|
|
257
259
|
trunk('0') |
|
258
260
|
# 7/10 digits for area code '2'.
|
259
261
|
match(/\A(2)\d{10}\z/) >> split(10) |
|
262
|
+
match(/\A(2)\d{8}\z/) >> split(8) |
|
260
263
|
one_of('2') >> split(7) |
|
261
264
|
# mobile
|
262
265
|
match(/\A([89]\d\d)\d{7}\z/) >> split(7) |
|
@@ -351,13 +354,13 @@ Phony.define do
|
|
351
354
|
|
352
355
|
# Côte d'Ivoire
|
353
356
|
# http://www.wtng.info/wtng-225-ci.html
|
354
|
-
#
|
357
|
+
# https://www.itu.int/dms_pub/itu-t/oth/02/02/T02020000310006PDFE.pdf
|
355
358
|
# http://en.wikipedia.org/wiki/Telephone_numbers_in_Ivory_Coast
|
356
359
|
#
|
357
360
|
# There is no trunk code for this country and several of the mobile prefixes start with 0
|
358
361
|
country '225',
|
359
362
|
trunk('', :normalize => false) |
|
360
|
-
fixed(2) >> split(2,2,2)
|
363
|
+
fixed(2) >> split(2,2,2,2)
|
361
364
|
|
362
365
|
country '226', none >> split(4,4) # Burkina Faso http://www.wtng.info/wtng-226-bf.html
|
363
366
|
country '227', none >> split(4,4) # Niger http://www.wtng.info/wtng-227-ne.html
|
@@ -382,8 +385,9 @@ Phony.define do
|
|
382
385
|
# Ghana
|
383
386
|
#
|
384
387
|
# From http://www.itu.int/oth/T0202000052/en
|
388
|
+
# https://en.wikipedia.org/wiki/Telephone_numbers_in_Ghana
|
385
389
|
#
|
386
|
-
country '233', fixed(2) >> split(3,4)
|
390
|
+
country '233', trunk('0') | fixed(2) >> split(3,4)
|
387
391
|
|
388
392
|
# Nigeria
|
389
393
|
# 3 4 split for mobile and 1 digit NDC, 3 2 or 3 3 otherwise
|
@@ -395,6 +399,7 @@ Phony.define do
|
|
395
399
|
country '234',
|
396
400
|
match(/^([7-9]0\d)\d+$/) >> split(3,4) | # Mobile
|
397
401
|
match(/^(81\d)\d+$/) >> split(3,4) | # Mobile
|
402
|
+
match(/^(91\d)\d+$/) >> split(3,4) | # Mobile
|
398
403
|
one_of('1', '2') >> split(3,3..4) | # Lagos, Ibadan
|
399
404
|
one_of('9') >> split(3,4) | # Abuja
|
400
405
|
one_of((30..79).map(&:to_s)) >> split(3,2..3) | # 2-digit NDC
|
@@ -407,7 +412,9 @@ Phony.define do
|
|
407
412
|
country '239', fixed(1) >> split(3,3) # Sao Tome and Principe, http://www.wtng.info/wtng-239-st.html
|
408
413
|
|
409
414
|
country '240', none >> split(3,3,3) # Equatorial Guinea
|
410
|
-
country '241',
|
415
|
+
country '241',
|
416
|
+
match(/^(\d)\d{6}$/) >> split(3,3) | # Gabonese Republic http://www.wtng.info/wtng-241-ga.html
|
417
|
+
match(/^(\d\d)\d{6}$/) >> split(2,2,2) # 2019 update https://en.wikipedia.org/wiki/Telephone_numbers_in_Gabon
|
411
418
|
country '242', # Congo http://www.wtng.info/wtng-242-cg.html
|
412
419
|
trunk('', :normalize => false) |
|
413
420
|
none >> split(4,5)
|
@@ -427,9 +434,9 @@ Phony.define do
|
|
427
434
|
# http://en.wikipedia.org/wiki/Telephone_numbers_in_Rwanda
|
428
435
|
country '250',
|
429
436
|
trunk('0') |
|
430
|
-
one_of('25')
|
431
|
-
match(/^(7[
|
432
|
-
one_of('06')
|
437
|
+
one_of('25') >> split(7) | # Geographic, fixed
|
438
|
+
match(/^(7[2389])/) >> split(7) | # Non-geographic, mobile
|
439
|
+
one_of('06') >> split(6) # Satellite
|
433
440
|
|
434
441
|
country '251', fixed(2) >> split(3, 4) # Ethiopia http://www.wtng.info/wtng-251-et.html
|
435
442
|
|
@@ -480,27 +487,31 @@ Phony.define do
|
|
480
487
|
# Zambia
|
481
488
|
# http://www.wtng.info/wtng-260-zm.html
|
482
489
|
# https://github.com/googlei18n/libphonenumber/
|
490
|
+
# https://en.wikipedia.org/wiki/Telephone_numbers_in_Zambia
|
483
491
|
country '260',
|
484
|
-
|
485
|
-
match(/^(
|
486
|
-
match(/^(
|
492
|
+
trunk('0') |
|
493
|
+
match(/^(76|77|95|96|97)/) >> split(3, 4) | # Mobile
|
494
|
+
match(/^(800)/) >> split(3,3) | # Toll free
|
495
|
+
match(/^(21[1-8])/) >> split(6) # Fixed
|
487
496
|
|
488
|
-
# Madagascar
|
497
|
+
# Madagascar
|
498
|
+
# https://en.wikipedia.org/wiki/Telephone_numbers_in_Madagascar
|
489
499
|
# http://www.itu.int/oth/T020200007F/en
|
490
500
|
country '261',
|
491
|
-
none >> matched_split(
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
)
|
501
|
+
# none >> matched_split(
|
502
|
+
# /\A20\d+\z/ => [2,2,3,2], # Telecom Malagasy (Telma)
|
503
|
+
# /\A32\d+\z/ => [2,2,3,2], # mobile Orange Madagascar
|
504
|
+
# /\A33\d+\z/ => [2,2,3,2], # mobile Airtel Madagascar
|
505
|
+
# /\A34\d+\z/ => [2,2,3,2], # mobile Telecom Malagasy (Telma)
|
506
|
+
# /\A38\d+\z/ => [2,2,3,2], # mobile Telecom Malagasy (Telma)
|
507
|
+
# /\A39\d+\z => [2,2,3,2] # mobile Blueline
|
508
|
+
# ),
|
509
|
+
match(/\A(20)\d+\z/) >> split(2,3,2) | # fix Telecom Malagasy (Telma)
|
510
|
+
match(/\A(32)\d+\z/) >> split(2,3,2) | # mobile Orange Madagascar
|
511
|
+
match(/\A(33)\d+\z/) >> split(2,3,2) | # mobile Airtel Madagascar
|
512
|
+
match(/\A(34)\d+\z/) >> split(2,3,2) | # mobile Telecom Malagasy (Telma)
|
513
|
+
match(/\A(38)\d+\z/) >> split(2,3,2) | # mobile Telecom Malagasy (Telma)
|
514
|
+
match(/\A(39)\d+\z/) >> split(2,3,2) # mobile Blueline Madagascar
|
504
515
|
|
505
516
|
country '262', # Reunion / Mayotte (new) http://www.wtng.info/wtng-262-fr.html
|
506
517
|
trunk('0') |
|
@@ -966,7 +977,7 @@ Phony.define do
|
|
966
977
|
/\A800\d+\z/ => [3,3], # freephone
|
967
978
|
/\A830\d+\z/ => [3,3], # shared cost
|
968
979
|
/\A60\d+\z/ => [3,3], # wireless geographic
|
969
|
-
/\A(72|75|76|77)\d+\z/ => [3,4], # mobile
|
980
|
+
/\A(71|72|75|76|77)\d+\z/ => [3,4], # mobile
|
970
981
|
/\A84\d+\z/ => [3,4], # wireless geographic
|
971
982
|
/\A\d+\z/ => [2,3] # geographic
|
972
983
|
)
|
@@ -987,7 +998,10 @@ Phony.define do
|
|
987
998
|
country '698', todo # -
|
988
999
|
country '699', todo # -
|
989
1000
|
|
990
|
-
|
1001
|
+
# International Freephone Service
|
1002
|
+
# https://www.itu.int/en/ITU-T/inr/unum/Pages/uifn.aspx
|
1003
|
+
country '800', none >> split(8)
|
1004
|
+
|
991
1005
|
country '801', todo # -
|
992
1006
|
country '802', todo # -
|
993
1007
|
country '803', todo # -
|
@@ -995,7 +1009,7 @@ Phony.define do
|
|
995
1009
|
country '805', todo # -
|
996
1010
|
country '806', todo # -
|
997
1011
|
country '807', todo # -
|
998
|
-
country '808',
|
1012
|
+
country '808', none >> split(12) # International Shared Cost Service (ISCS)
|
999
1013
|
country '809', todo # -
|
1000
1014
|
|
1001
1015
|
country '830', todo # -
|
data/lib/phony/country.rb
CHANGED
@@ -97,6 +97,9 @@ module Phony
|
|
97
97
|
end
|
98
98
|
end
|
99
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
|
100
103
|
case type
|
101
104
|
when String
|
102
105
|
trunk &&= trunk.format(space, use_trunk)
|
@@ -125,6 +128,7 @@ module Phony
|
|
125
128
|
end
|
126
129
|
end
|
127
130
|
def format_ndc ndc, parentheses
|
131
|
+
ndc = nil if ndc == false # TODO
|
128
132
|
parentheses ? "(#{ndc})" : ndc
|
129
133
|
end
|
130
134
|
def format_with_ndc format, cc, ndc, local, space
|
@@ -156,10 +160,12 @@ module Phony
|
|
156
160
|
#
|
157
161
|
# In some cases it doesn't, like Italy.
|
158
162
|
#
|
159
|
-
|
163
|
+
# Note: Options such as CC
|
164
|
+
#
|
165
|
+
def normalize national_number, options = {}
|
160
166
|
clean! national_number
|
161
167
|
normalized = @codes.reduce national_number do |number, code|
|
162
|
-
result = code.normalize number
|
168
|
+
result = code.normalize number, options
|
163
169
|
break result if result
|
164
170
|
number
|
165
171
|
end
|
data/lib/phony/country_codes.rb
CHANGED
@@ -66,7 +66,7 @@ module Phony
|
|
66
66
|
country, cc, number = partial_split number
|
67
67
|
country
|
68
68
|
end
|
69
|
-
number = country.normalize number
|
69
|
+
number = country.normalize number, cc: cc
|
70
70
|
countrify! number, cc
|
71
71
|
end
|
72
72
|
|
@@ -97,7 +97,7 @@ module Phony
|
|
97
97
|
|
98
98
|
# False if it fails the basic check.
|
99
99
|
#
|
100
|
-
return false unless (4..16) === normalized.size
|
100
|
+
return false unless (4..16) === normalized.size # unless hints[:check_length] == false
|
101
101
|
|
102
102
|
country, cc, rest = partial_split normalized
|
103
103
|
|
data/lib/phony/dsl.rb
CHANGED
data/lib/phony/national_code.rb
CHANGED
@@ -31,9 +31,7 @@ module Phony
|
|
31
31
|
# since using nil is dangerous and breaks
|
32
32
|
# abstraction)
|
33
33
|
#
|
34
|
-
# Note:
|
35
|
-
#
|
36
|
-
# TODO Flip nil/false?
|
34
|
+
# Note: Decided it stays in. When formatting, it's turned into nil.
|
37
35
|
#
|
38
36
|
def split national_number
|
39
37
|
[nil, false, national_number]
|
data/lib/phony/trunk_code.rb
CHANGED
@@ -6,9 +6,9 @@ module Phony
|
|
6
6
|
# * code: The trunk code, e.g. 0.
|
7
7
|
#
|
8
8
|
# Options:
|
9
|
-
# * normalize: Remove the trunk code when normalizing (only use if number scheme is defined unambiguously).
|
10
|
-
# * split: Remove the trunk code when splitting (only use if number scheme is defined unambiguously).
|
11
|
-
# * format: Add the trunk code when formatting (passing `false` will not add it).
|
9
|
+
# * normalize: [true (default), false] Remove the trunk code when normalizing (only use if number scheme is defined unambiguously).
|
10
|
+
# * split: [true, false (default)] Remove the trunk code when splitting (only use if number scheme is defined unambiguously).
|
11
|
+
# * format: [true (default), false] Add the trunk code when formatting (passing `false` will not add it).
|
12
12
|
#
|
13
13
|
def initialize code, options = {}
|
14
14
|
@code = code
|
@@ -35,8 +35,8 @@ module Phony
|
|
35
35
|
|
36
36
|
# Normalize normalizes the given national number.
|
37
37
|
#
|
38
|
-
def normalize national_number
|
39
|
-
national_number.gsub! @trunk_code_replacement, EMPTY_STRING if @normalize
|
38
|
+
def normalize national_number, options = {}
|
39
|
+
national_number.gsub! @trunk_code_replacement, EMPTY_STRING if @normalize && options[:cc]
|
40
40
|
return national_number
|
41
41
|
end
|
42
42
|
|
@@ -192,7 +192,7 @@ describe 'plausibility' do
|
|
192
192
|
Phony.plausible?('+385 60 12 345').should be_truthy # Premium rate
|
193
193
|
Phony.plausible?('+385 62 123 456').should be_truthy # Premium, personal and UAN
|
194
194
|
end
|
195
|
-
it_is_correct_for "Côte d'Ivoire", :samples => '+225
|
195
|
+
it_is_correct_for "Côte d'Ivoire", :samples => '+225 01 9358 8764'
|
196
196
|
it_is_correct_for 'Democratic Republic of Timor-Leste', :samples => ['+670 465 7886', '+670 7465 7886']
|
197
197
|
it_is_correct_for 'Democratic Republic of the Congo', :samples => '+243 80 864 9794'
|
198
198
|
it_is_correct_for 'Diego Garcia', :samples => '+246 123 7686'
|
@@ -249,7 +249,14 @@ describe 'plausibility' do
|
|
249
249
|
end
|
250
250
|
it_is_correct_for 'French Guiana (French Department of)', :samples => '+594 594 123 456'
|
251
251
|
it_is_correct_for "French Polynesia (Territoire français d'outre-mer)", :samples => '+689 87 27 84 00'
|
252
|
-
|
252
|
+
it 'is correct for Gabon' do
|
253
|
+
Phony.plausible?('+241 1 627 739').should be_truthy
|
254
|
+
Phony.plausible?('+241 12 34 56 78').should be_truthy
|
255
|
+
end
|
256
|
+
# it_is_correct_for 'Gabonese Republic', :samples => [
|
257
|
+
# '+241 1 627 739',
|
258
|
+
# '+241 12 34 56 78',
|
259
|
+
# ]
|
253
260
|
it_is_correct_for 'Gambia', :samples => '+220 989 5148'
|
254
261
|
it_is_correct_for 'Germany', :samples => [
|
255
262
|
'+49 69 155 1',
|
@@ -273,6 +280,7 @@ describe 'plausibility' do
|
|
273
280
|
it_is_correct_for 'Guinea-Bissau', :samples => '+245 44 728 6998'
|
274
281
|
it_is_correct_for 'Guyana', :samples => '+592 263 1234'
|
275
282
|
it_is_correct_for 'Honduras (Republic of)', :samples => '+504 12 961 637'
|
283
|
+
it_is_correct_for 'Italy', :samples => ['+39 0574 1234']
|
276
284
|
it_is_correct_for 'Iraq', :samples => ['+964 1 123 4567',
|
277
285
|
'+964 21 113 456',
|
278
286
|
'+964 71 1234 5678']
|
@@ -317,10 +325,19 @@ describe 'plausibility' do
|
|
317
325
|
it_is_correct_for 'Macedonia', :samples => ['+389 2 123 4567',
|
318
326
|
'+389 7 124 3456',
|
319
327
|
'+389 7 234 5678']
|
320
|
-
it_is_correct_for 'Madagascar', :samples => ['+261 20
|
321
|
-
'+261
|
322
|
-
'+261
|
323
|
-
'+261
|
328
|
+
it_is_correct_for 'Madagascar', :samples => ['+261 20 23 456 78',
|
329
|
+
'+261 32 34 546 78',
|
330
|
+
'+261 33 34 546 78',
|
331
|
+
'+261 34 34 546 78',
|
332
|
+
'+261 38 34 546 78']
|
333
|
+
it 'is incorrect for Madagascar' do
|
334
|
+
Phony.plausible?('+261 20 012 345 678').should be_falsey
|
335
|
+
Phony.plausible?('+261 20 12 434 569').should be_falsey
|
336
|
+
Phony.plausible?('+261 51 23 4567 8').should be_falsey
|
337
|
+
Phony.plausible?('+261 34 345 46789').should be_falsey
|
338
|
+
Phony.plausible?('+261 34 345 467').should be_falsey
|
339
|
+
end
|
340
|
+
|
324
341
|
it_is_correct_for 'Malawi', :samples => ['+265 1725 123',
|
325
342
|
'+265 213 456 789',
|
326
343
|
'+265 9123 456',
|
@@ -392,6 +409,12 @@ describe 'plausibility' do
|
|
392
409
|
'+507 6 123 4567',
|
393
410
|
'+507 2 123 456']
|
394
411
|
it_is_correct_for 'Reunion / Mayotte (new)', :samples => '+262 295 276 964'
|
412
|
+
it_is_correct_for 'Rwanda', :samples => ['+250 72 1234567',
|
413
|
+
'+250 73 1234567',
|
414
|
+
'+250 78 1234567',
|
415
|
+
'+250 79 1234567',
|
416
|
+
'+250 25 1234567',
|
417
|
+
'+250 06 123456']
|
395
418
|
it_is_correct_for 'Saint Helena', :samples => '+290 5134'
|
396
419
|
it_is_correct_for 'Saint Pierre and Miquelon (Collectivité territoriale de la République française)', :samples => '+508 474 714'
|
397
420
|
it_is_correct_for 'Salvador (El)', :samples => [
|
@@ -420,8 +443,10 @@ describe 'plausibility' do
|
|
420
443
|
['+381 11 123 456', '+381 11 123 4567'],
|
421
444
|
'+381 72 123 456',
|
422
445
|
'+381 60 123',
|
423
|
-
'+381 60 123 4567',
|
446
|
+
['+381 60 123 4567', '+381 69 123 456'],
|
424
447
|
'+381 42 123 456',
|
448
|
+
'+381 677 123 456',
|
449
|
+
'+381 678 123 456',
|
425
450
|
'+381 9 123 4567',
|
426
451
|
'+381 60 123',
|
427
452
|
'+381 60 123 456 7890',
|
@@ -492,7 +517,10 @@ describe 'plausibility' do
|
|
492
517
|
it_is_correct_for 'Lybia', :samples => ['+218 205 123 45',
|
493
518
|
'+218 22 123 456',
|
494
519
|
'+218 21 1234 456',
|
495
|
-
'+218 91 1234 456'
|
520
|
+
'+218 91 1234 456',
|
521
|
+
'+218 92 1234 456',
|
522
|
+
'+218 94 1234 456',
|
523
|
+
'+218 95 1234 456']
|
496
524
|
it_is_correct_for 'Mongolia', :samples => ['+976 11 123 45',
|
497
525
|
['+976 121 12 34', '+976 121 12 345'],
|
498
526
|
'+976 70 123 456',
|
@@ -553,9 +581,12 @@ describe 'plausibility' do
|
|
553
581
|
'+967 58 1234']
|
554
582
|
it 'is correct for Zambia' do
|
555
583
|
Phony.plausible?('+260 211 123456').should be_truthy # Fixed
|
556
|
-
Phony.plausible?('+260
|
557
|
-
Phony.plausible?('+260
|
558
|
-
Phony.plausible?('+260
|
584
|
+
Phony.plausible?('+260 96 512 4567').should be_truthy # MTN Mobile
|
585
|
+
Phony.plausible?('+260 97 712 3456').should be_truthy # Airtel Mobile
|
586
|
+
Phony.plausible?('+260 95 512 4567').should be_truthy # Zamtel Mobile
|
587
|
+
Phony.plausible?('+260 96 512 456').should be_falsy # MTN Mobile (Too short)
|
588
|
+
Phony.plausible?('+260 97 812 345').should be_falsy # Airtel Mobile (Too short)
|
589
|
+
Phony.plausible?('+260 95 512 345').should be_falsy # Zamtel Mobile (Too short)
|
559
590
|
Phony.plausible?('+260 800 123 456').should be_truthy # Toll free
|
560
591
|
end
|
561
592
|
it_is_correct_for 'Zimbabwe', :samples => [['+263 2582 123 456', '+263 2582 123'],
|
@@ -607,6 +638,7 @@ describe 'plausibility' do
|
|
607
638
|
end
|
608
639
|
|
609
640
|
it 'is correct for Philippine' do
|
641
|
+
Phony.plausible?('+63 2 89889999').should be_truthy
|
610
642
|
Phony.plausible?('+63 976 1234567').should be_truthy # mobile phone with area code 9
|
611
643
|
Phony.plausible?('+63 876 1234567').should be_truthy # mobile phone with area code 8
|
612
644
|
end
|
@@ -103,8 +103,17 @@ describe 'country descriptions' do
|
|
103
103
|
it_splits '3295551914', ['32', '9', '555', '19', '14'] # Gent
|
104
104
|
it_splits '3245551414', ['32', '4', '555', '14', '14'] # Liège
|
105
105
|
it_splits '3216473200', ['32', '16', '47', '32', '00'] # Leuven
|
106
|
-
it_splits '
|
107
|
-
it_splits '
|
106
|
+
it_splits '32455123456', ['32', '455', '12', '34', '56'] # mobile (Voo)
|
107
|
+
it_splits '32456123456', ['32', '456', '12', '34', '56'] # mobile (MobileViking)
|
108
|
+
it_splits '32460123456', ['32', '460', '12', '34', '56'] # mobile (Proximus)
|
109
|
+
it_splits '32465123456', ['32', '465', '12', '34', '56'] # mobile (Lycamobile)
|
110
|
+
it_splits '32466123456', ['32', '466', '12', '34', '56'] # mobile (Vectone)
|
111
|
+
it_splits '32467123456', ['32', '467', '12', '34', '56'] # mobile (Telenet)
|
112
|
+
it_splits '32468123456', ['32', '468', '12', '34', '56'] # mobile (Telenet)
|
113
|
+
it_splits '32469123456', ['32', '469', '12', '34', '56'] # mobile ()
|
114
|
+
it_splits '32475123456', ['32', '475', '12', '34', '56'] # mobile (Proximus)
|
115
|
+
it_splits '32485123456', ['32', '485', '12', '34', '56'] # mobile (Telenet)
|
116
|
+
it_splits '32495123456', ['32', '495', '12', '34', '56'] # mobile (Orange)
|
108
117
|
it_splits '3270123123', ['32', '70', '123', '123'] # Bus Service?
|
109
118
|
it_splits '3278123123', ['32', '78', '123', '123'] # National rate service
|
110
119
|
it_splits '3290123123', ['32', '901', '23', '123'] # National rate service
|
@@ -214,6 +223,21 @@ describe 'country descriptions' do
|
|
214
223
|
describe 'China' do
|
215
224
|
it_splits '862112345678', ['86', '21', '1234', '5678'] # Shanghai
|
216
225
|
it_splits '8675582193447', ['86', '755', '8219', '3447'] # Shenzhen
|
226
|
+
it_splits '869511234567', ['86', '951', '123', '4567'] # Yinchuan
|
227
|
+
|
228
|
+
context 'mobile numbers' do
|
229
|
+
%w{
|
230
|
+
130 131 132 133 134 135 136 137 138 139
|
231
|
+
145 146 147 148 149
|
232
|
+
150 151 152 153 155 156 157 158 159
|
233
|
+
162 165 166 167
|
234
|
+
170 171 172 173 174 175 176 177 178
|
235
|
+
180 181 182 183 184 185 186 187 188 189
|
236
|
+
190 191 192 193 195 196 197 198 199
|
237
|
+
}.each do |prefix|
|
238
|
+
it_splits "86#{prefix}12345678", ['86', prefix, '1234', '5678']
|
239
|
+
end
|
240
|
+
end
|
217
241
|
end
|
218
242
|
describe 'Colombia' do
|
219
243
|
it_splits '5711234567', ['57', '1', '123', '4567']
|
@@ -446,6 +470,7 @@ describe 'country descriptions' do
|
|
446
470
|
it_splits '3903123391', ['39', '031', '23391'] # Como
|
447
471
|
it_splits '390909709511', ['39', '090', '9709511'] # Barcellona
|
448
472
|
it_splits '390471811353', ['39', '0471', '811', '353'] # Bolzano
|
473
|
+
it_splits '3905745730', ['39', '0574', '5730'] # Prato
|
449
474
|
end
|
450
475
|
describe 'Japan' do
|
451
476
|
it_splits '81312345678', %w(81 3 1234 5678) # Tokyo
|
@@ -461,6 +486,8 @@ describe 'country descriptions' do
|
|
461
486
|
it_splits '817012345678', %w(81 70 1234 5678) # PHS
|
462
487
|
it_splits '818012345678', %w(81 80 1234 5678) # Cellular
|
463
488
|
it_splits '819012345678', %w(81 90 1234 5678) # Cellular
|
489
|
+
it_splits '810570123456', %w(81 570 123 456) # Navi-dial
|
490
|
+
it_splits '810180123456', %w(81 180 123 456) # Tele-gong/Tele-dome
|
464
491
|
end
|
465
492
|
describe 'Kenya' do
|
466
493
|
it_splits '254201234567', ['254', '20', '1234567'] # Nairobi
|
@@ -598,6 +625,7 @@ describe 'country descriptions' do
|
|
598
625
|
end
|
599
626
|
describe 'Philippines' do
|
600
627
|
it_splits '6321234567', ['63', '2', '1234567']
|
628
|
+
it_splits '63289889999', ['63', '2', '89889999']
|
601
629
|
it_splits '6321234567890', ['63', '2', '1234567890']
|
602
630
|
it_splits '632123456789012', ['63', '2', '123456789012']
|
603
631
|
it_splits '639121234567', ['63', '912', '1234567']
|
@@ -653,6 +681,7 @@ describe 'country descriptions' do
|
|
653
681
|
it_splits '250781234567', ['250', '78', '1234567'] # mobile
|
654
682
|
it_splits '250721234567', ['250', '72', '1234567'] # mobile
|
655
683
|
it_splits '250731234567', ['250', '73', '1234567'] # mobile
|
684
|
+
it_splits '250791234567', ['250', '79', '1234567'] # mobile
|
656
685
|
it_splits '250251234567', ['250', '25', '1234567'] # fixed
|
657
686
|
it_splits '25006123456', ['250', '06', '123456'] # fixed
|
658
687
|
end
|
@@ -735,6 +764,7 @@ describe 'country descriptions' do
|
|
735
764
|
describe 'Switzerland' do
|
736
765
|
it_splits '41443643532', ['41', '44', '364', '35', '32'] # Zurich (usually)
|
737
766
|
it_splits '41800334455', ['41', '800', '334', '455'] # Service number
|
767
|
+
it_splits '41860443643532', ['41', '860', '44', '364', '35', '32'] # Voicemail access
|
738
768
|
it_splits '41900123456', ['41', '900', '123', '456'] # Business Number
|
739
769
|
it_splits '41901123456', ['41', '901', '123', '456'] # Business Number Entertainment
|
740
770
|
it_splits '41906123456', ['41', '906', '123', '456'] # Business Number Adult Entertainment
|
@@ -823,9 +853,9 @@ describe 'country descriptions' do
|
|
823
853
|
end
|
824
854
|
describe 'Zambia' do
|
825
855
|
it_splits '260211123456', ['260', '211', '123456'] # Fixed
|
826
|
-
it_splits '260955123456', ['260', '
|
827
|
-
it_splits '260967123456', ['260', '
|
828
|
-
it_splits '260978123456', ['260', '
|
856
|
+
it_splits '260955123456', ['260', '95', '512', '3456'] # Mobile
|
857
|
+
it_splits '260967123456', ['260', '96', '712', '3456'] # Mobile
|
858
|
+
it_splits '260978123456', ['260', '97', '812', '3456'] # Mobile
|
829
859
|
it_splits '260800123456', ['260', '800', '123', '456'] # Toll free
|
830
860
|
end
|
831
861
|
describe 'New Zealand' do
|
@@ -871,8 +901,8 @@ describe 'country descriptions' do
|
|
871
901
|
it_splits '50622345678', %w(506 2 234 5678)
|
872
902
|
end
|
873
903
|
describe "Côte d'Ivoire" do
|
874
|
-
it_splits '
|
875
|
-
it_splits '
|
904
|
+
it_splits '2250107335518', ['225', '01', '07', '33', '55', '18']
|
905
|
+
it_splits '2250237335518', ['225', '02', '37', '33', '55', '18']
|
876
906
|
end
|
877
907
|
describe 'Democratic Republic of Timor-Leste' do
|
878
908
|
it_splits '6701742945', ['670', false, '174', '2945']
|
@@ -935,6 +965,7 @@ describe 'country descriptions' do
|
|
935
965
|
end
|
936
966
|
describe 'Gabonese Republic' do
|
937
967
|
it_splits '2411834375', ['241', '1', '834', '375']
|
968
|
+
it_splits '24174012345', ['241', '74', '01', '23', '45']
|
938
969
|
end
|
939
970
|
describe 'Gambia' do
|
940
971
|
it_splits '2206683355', ['220', false, '668', '3355']
|
@@ -1022,11 +1053,14 @@ describe 'country descriptions' do
|
|
1022
1053
|
it_splits '21822123456', %w(218 22 123 456)
|
1023
1054
|
it_splits '218211234456', %w(218 21 1234 456)
|
1024
1055
|
it_splits '218911234456', %w(218 91 1234 456)
|
1056
|
+
it_splits '218941234456', %w(218 94 1234 456)
|
1057
|
+
it_splits '218951234456', %w(218 95 1234 456)
|
1025
1058
|
end
|
1026
1059
|
describe 'Madagascar' do
|
1027
|
-
it_splits '
|
1028
|
-
it_splits '
|
1029
|
-
it_splits '
|
1060
|
+
it_splits '261202254716', ['261', '20', *%w(22 547 16)]
|
1061
|
+
it_splits '261320254716', ['261', '32', *%w(02 547 16)]
|
1062
|
+
it_splits '261330254716', ['261', '33', *%w(02 547 16)]
|
1063
|
+
it_splits '261340254716', ['261', '34', *%w(02 547 16)]
|
1030
1064
|
end
|
1031
1065
|
describe 'Malawi' do
|
1032
1066
|
it_splits '2651725123', ['265', false, '1725', '123']
|
@@ -1139,6 +1173,17 @@ describe 'country descriptions' do
|
|
1139
1173
|
it_splits '2349087661234', %w(234 908 766 1234)
|
1140
1174
|
it_splits '2349097661234', %w(234 909 766 1234)
|
1141
1175
|
|
1176
|
+
it_splits '2349107661234', %w(234 910 766 1234)
|
1177
|
+
it_splits '2349117661234', %w(234 911 766 1234)
|
1178
|
+
it_splits '2349127661234', %w(234 912 766 1234)
|
1179
|
+
it_splits '2349137661234', %w(234 913 766 1234)
|
1180
|
+
it_splits '2349147661234', %w(234 914 766 1234)
|
1181
|
+
it_splits '2349157661234', %w(234 915 766 1234)
|
1182
|
+
it_splits '2349167661234', %w(234 916 766 1234)
|
1183
|
+
it_splits '2349177661234', %w(234 917 766 1234)
|
1184
|
+
it_splits '2349187661234', %w(234 918 766 1234)
|
1185
|
+
it_splits '2349197661234', %w(234 919 766 1234)
|
1186
|
+
|
1142
1187
|
it_splits '2348107661234', %w(234 810 766 1234)
|
1143
1188
|
it_splits '2348117661234', %w(234 811 766 1234)
|
1144
1189
|
it_splits '2348127661234', %w(234 812 766 1234)
|
@@ -1190,6 +1235,7 @@ describe 'country descriptions' do
|
|
1190
1235
|
describe 'Samoa (Independent State of)' do
|
1191
1236
|
it_splits '685800123', ['685', false, '800', '123']
|
1192
1237
|
it_splits '68561123', ['685', false, '61', '123']
|
1238
|
+
it_splits '6857112345', ['685', false, '711', '2345']
|
1193
1239
|
it_splits '6857212345', ['685', false, '721', '2345']
|
1194
1240
|
it_splits '685830123', ['685', false, '830', '123']
|
1195
1241
|
it_splits '685601234', ['685', false, '601', '234']
|
@@ -1278,6 +1324,7 @@ describe 'country descriptions' do
|
|
1278
1324
|
it_splits '88633123456', %w(886 3 312 3456)
|
1279
1325
|
it_splits '88637123456', %w(886 37 12 3456)
|
1280
1326
|
it_splits '88682712345', %w(886 82 71 2345)
|
1327
|
+
it_splits '886801123123', %w(886 801 123 123)
|
1281
1328
|
it_splits '88689712345', %w(886 89 71 2345)
|
1282
1329
|
it_splits '88682672345', %w(886 826 7 2345)
|
1283
1330
|
it_splits '88683672345', %w(886 836 7 2345)
|
@@ -1388,6 +1435,14 @@ describe 'country descriptions' do
|
|
1388
1435
|
it_splits number, ['263', prefix, '234', '5678']
|
1389
1436
|
end
|
1390
1437
|
end
|
1438
|
+
|
1439
|
+
describe 'Universal International Freephone' do
|
1440
|
+
it_splits '80012345678', ['800', false, '12345678']
|
1441
|
+
end
|
1442
|
+
|
1443
|
+
describe 'Shared-Cost Service' do
|
1444
|
+
it_splits '80812345678', ['808', false, '12345678']
|
1445
|
+
end
|
1391
1446
|
end
|
1392
1447
|
|
1393
1448
|
end
|
@@ -1,32 +1,30 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Phony::CountryCodes do
|
4
|
-
|
5
|
-
|
6
|
-
@countries = Phony::CountryCodes.instance
|
7
|
-
end
|
4
|
+
|
5
|
+
let(:countries) { Phony::CountryCodes.instance }
|
8
6
|
|
9
7
|
describe '#[]' do
|
10
8
|
it 'returns a country' do
|
11
|
-
|
9
|
+
countries['41'].class.should eql Phony::Country
|
12
10
|
end
|
13
11
|
end
|
14
12
|
|
15
13
|
describe '#country_for' do
|
16
14
|
it 'returns a country' do
|
17
|
-
|
15
|
+
countries.send(:country_for, '41').class.should eql Phony::Country
|
18
16
|
end
|
19
17
|
end
|
20
18
|
|
21
19
|
describe '#countrify' do
|
22
20
|
it 'returns a country' do
|
23
|
-
|
21
|
+
countries.send(:countrify, '441231212', '41').should eql '41441231212'
|
24
22
|
end
|
25
23
|
end
|
26
24
|
describe '#countrify!' do
|
27
25
|
it 'in-place replaces the number' do
|
28
26
|
number = '441231212'
|
29
|
-
|
27
|
+
countries.send(:countrify!, number, '41').should eql number
|
30
28
|
|
31
29
|
number.should == '41441231212'
|
32
30
|
end
|
@@ -34,127 +32,127 @@ describe Phony::CountryCodes do
|
|
34
32
|
|
35
33
|
describe '#vanity?' do
|
36
34
|
it 'returns true if so' do
|
37
|
-
|
35
|
+
countries.vanity?('1800HELLOES').should eql true
|
38
36
|
end
|
39
37
|
it 'returns false if not' do
|
40
|
-
|
38
|
+
countries.vanity?('18001234567').should eql false
|
41
39
|
end
|
42
40
|
end
|
43
41
|
|
44
42
|
describe 'normalize' do
|
45
43
|
it 'normalizes correctly' do
|
46
|
-
|
44
|
+
countries.normalize('0041-44-364-35-32').should eql '41443643532'
|
47
45
|
end
|
48
46
|
it 'normalizes correctly with CC option' do
|
49
|
-
|
47
|
+
countries.normalize('044-364-35-32', cc: '41').should eql '41443643532'
|
50
48
|
end
|
51
49
|
|
52
50
|
context 'specific countries' do
|
53
51
|
it 'handles Congo correctly' do
|
54
|
-
|
55
|
-
|
52
|
+
countries.normalize('+242 0571 73992').should eql '242057173992'
|
53
|
+
countries.normalize('+242 2221 15932').should eql '242222115932'
|
56
54
|
end
|
57
55
|
end
|
58
56
|
end
|
59
57
|
|
60
58
|
describe 'formatted' do
|
61
59
|
it 'formats correctly' do
|
62
|
-
|
60
|
+
countries.formatted('41443643532', :format => :international, :spaces => :-).should eql '+41-44-364-35-32'
|
63
61
|
end
|
64
62
|
it 'formats correctly' do
|
65
|
-
|
63
|
+
countries.formatted('41443643532', :format => :international_relative, :spaces => :-).should eql '0041-44-364-35-32'
|
66
64
|
end
|
67
65
|
it 'formats correctly' do
|
68
|
-
|
66
|
+
countries.formatted('41443643532', :format => :national, :spaces => :-).should eql '044-364-35-32'
|
69
67
|
end
|
70
68
|
context 'specific' do
|
71
69
|
it 'formats Ireland correctly' do
|
72
|
-
|
70
|
+
countries.formatted("3533451234", :format => :national).should eql '0345 1234'
|
73
71
|
end
|
74
72
|
it 'formats Ireland correctly' do
|
75
|
-
|
73
|
+
countries.formatted("353411231234", :format => :national).should eql '041 123 1234'
|
76
74
|
end
|
77
75
|
it 'formats Spain correctly' do
|
78
|
-
|
76
|
+
countries.formatted("34123456789", :format => :national).should eql '123 456 789'
|
79
77
|
end
|
80
78
|
it 'formats Cambodia correctly' do
|
81
|
-
|
79
|
+
countries.formatted('85512239123', :format => :national).should eql '012 239 123'
|
82
80
|
end
|
83
81
|
it 'formats the US correctly' do
|
84
|
-
|
82
|
+
countries.formatted('18005551212', :format => :national, :spaces => :-).should eql '(800)-555-1212'
|
85
83
|
end
|
86
84
|
it 'formats the US correctly' do
|
87
|
-
|
85
|
+
countries.formatted('18005551212', :format => :national, :spaces => :-).should eql '(800)-555-1212'
|
88
86
|
end
|
89
87
|
end
|
90
88
|
context 'default' do
|
91
89
|
it "should format swiss numbers" do
|
92
|
-
|
90
|
+
countries.formatted('41443643532').should eql '+41 44 364 35 32'
|
93
91
|
end
|
94
92
|
it "should format swiss service numbers" do
|
95
|
-
|
93
|
+
countries.formatted('41800112233').should eql '+41 800 112 233'
|
96
94
|
end
|
97
95
|
it "should format austrian numbers" do
|
98
|
-
|
96
|
+
countries.formatted('43198110').should eql '+43 1 98110'
|
99
97
|
end
|
100
98
|
it "should format american numbers" do
|
101
|
-
|
99
|
+
countries.formatted('18705551122').should eql '+1 (870) 555-1122'
|
102
100
|
end
|
103
101
|
it "should format irish numbers" do
|
104
|
-
|
102
|
+
countries.formatted('35311234567').should eql '+353 1 123 4567'
|
105
103
|
end
|
106
104
|
end
|
107
105
|
describe "international" do
|
108
106
|
it "should format north american numbers" do
|
109
|
-
|
107
|
+
countries.formatted('18091231234', :format => :international).should eql '+1 (809) 123-1234'
|
110
108
|
end
|
111
109
|
it "should format austrian numbers" do
|
112
|
-
|
110
|
+
countries.formatted('43198110', :format => :international).should eql '+43 1 98110'
|
113
111
|
end
|
114
112
|
it "should format austrian numbers" do
|
115
|
-
|
113
|
+
countries.formatted('43198110', :format => :international_absolute).should eql '+43 1 98110'
|
116
114
|
end
|
117
115
|
it "should format french numbers" do
|
118
|
-
|
116
|
+
countries.formatted('33142278186', :format => :+).should eql '+33 1 42 27 81 86'
|
119
117
|
end
|
120
118
|
it "should format austrian numbers" do
|
121
|
-
|
119
|
+
countries.formatted('43198110', :format => :international_relative).should eql '0043 1 98110'
|
122
120
|
end
|
123
121
|
it 'should format liechtensteiner numbers' do
|
124
|
-
|
122
|
+
countries.formatted('4233841148', :format => :international_relative).should eql '00423 384 11 48'
|
125
123
|
end
|
126
124
|
it "should format irish numbers" do
|
127
|
-
|
125
|
+
countries.formatted('35311234567', :format => :international).should eql '+353 1 123 4567'
|
128
126
|
end
|
129
127
|
it "should format luxembourgian numbers" do
|
130
|
-
|
128
|
+
countries.formatted('352222809', :format => :international).should eql '+352 22 28 09'
|
131
129
|
end
|
132
130
|
it "should format luxembourgian 4-digit ndc numbers" do
|
133
|
-
|
131
|
+
countries.formatted('35226222809', :format => :international).should eql '+352 2622 28 09'
|
134
132
|
end
|
135
133
|
it "should format luxembourgian mobile numbers" do
|
136
|
-
|
134
|
+
countries.formatted('352621123456', :format => :international).should eql '+352 621 123 456'
|
137
135
|
end
|
138
136
|
it "should format luxembourgian city numbers" do
|
139
|
-
|
137
|
+
countries.formatted('3524123456', :format => :international).should eql '+352 41 23 45 6'
|
140
138
|
end
|
141
139
|
it "should format luxembourgian machine to machine numbers" do
|
142
|
-
|
140
|
+
countries.formatted('352602112345678', :format => :international).should eql '+352 6021 12 34 56 78'
|
143
141
|
end
|
144
142
|
it "should format luxembourgian numbers" do
|
145
|
-
|
143
|
+
countries.formatted('352370431', :format => :international).should eql '+352 37 04 31'
|
146
144
|
end
|
147
145
|
it "should format luxembourgian numbers" do
|
148
|
-
|
146
|
+
countries.formatted('35227855', :format => :international).should eql '+352 27 85 5'
|
149
147
|
end
|
150
148
|
it "should format nigerian lagosian numbers" do
|
151
|
-
|
149
|
+
countries.formatted('23414480000', :format => :international).should eql '+234 1 448 0000'
|
152
150
|
end
|
153
151
|
it "should format nigerian beninese numbers" do
|
154
|
-
|
152
|
+
countries.formatted('23452123456', :format => :international).should eql '+234 52 123 456'
|
155
153
|
end
|
156
154
|
it "should format nigerian mobile numbers" do
|
157
|
-
|
155
|
+
countries.formatted('2347061234567', :format => :international).should eql '+234 706 123 4567'
|
158
156
|
end
|
159
157
|
context 'with no spaces' do
|
160
158
|
it "should format north american numbers" do
|
@@ -43,6 +43,18 @@ describe Phony::Country do
|
|
43
43
|
Phony.normalize('+378903549').should == '3780549903549'
|
44
44
|
end
|
45
45
|
end
|
46
|
+
describe 'Japan' do
|
47
|
+
it 'normalizes correctly' do
|
48
|
+
Phony.normalize('+81-03-1234-5634').should == '81312345634'
|
49
|
+
Phony.normalize('03-1234-5634', cc: '81').should == '81312345634'
|
50
|
+
end
|
51
|
+
it 'formats correctly' do
|
52
|
+
Phony.format('81312345634').should == '+81-3-1234-5634'
|
53
|
+
end
|
54
|
+
it 'splits correctly' do
|
55
|
+
Phony.split('81312345634').should == %w(81 3 1234 5634)
|
56
|
+
end
|
57
|
+
end
|
46
58
|
end
|
47
59
|
|
48
60
|
context "without special cases (with switzerland)" do
|
@@ -89,4 +101,4 @@ describe Phony::Country do
|
|
89
101
|
end
|
90
102
|
end
|
91
103
|
|
92
|
-
end
|
104
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Phony::TrunkCode do
|
4
|
+
|
5
|
+
describe '#format' do
|
6
|
+
it 'is correct' do
|
7
|
+
code = described_class.new('0')
|
8
|
+
expect(code.format('%s %s')).to eq '0'
|
9
|
+
end
|
10
|
+
it 'is correct' do
|
11
|
+
code = described_class.new('0', format: true)
|
12
|
+
expect(code.format('%s %s')).to eq '0'
|
13
|
+
end
|
14
|
+
it 'is correct' do
|
15
|
+
code = described_class.new('0', format: false)
|
16
|
+
expect(code.format('%s %s')).to eq nil
|
17
|
+
end
|
18
|
+
it 'is correct' do
|
19
|
+
code = described_class.new('06')
|
20
|
+
expect(code.format('%s %s')).to eq '06'
|
21
|
+
end
|
22
|
+
it 'is correct' do
|
23
|
+
code = described_class.new('06', format: true)
|
24
|
+
expect(code.format('%s %s')).to eq '06'
|
25
|
+
end
|
26
|
+
it 'is correct' do
|
27
|
+
code = described_class.new('06', format: false)
|
28
|
+
expect(code.format('%s %s')).to eq nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#normalize' do
|
33
|
+
it 'is correct' do
|
34
|
+
code = described_class.new('0')
|
35
|
+
expect(code.normalize('0123')).to eq '0123'
|
36
|
+
end
|
37
|
+
it 'is correct' do
|
38
|
+
code = described_class.new('0', normalize: true)
|
39
|
+
expect(code.normalize('0123')).to eq '0123'
|
40
|
+
end
|
41
|
+
it 'is correct' do
|
42
|
+
code = described_class.new('0', normalize: false)
|
43
|
+
expect(code.normalize('0123')).to eq '0123'
|
44
|
+
end
|
45
|
+
it 'is correct' do
|
46
|
+
code = described_class.new('06')
|
47
|
+
expect(code.normalize('06123')).to eq '06123'
|
48
|
+
end
|
49
|
+
it 'is correct' do
|
50
|
+
code = described_class.new('06', normalize: true)
|
51
|
+
expect(code.normalize('06123')).to eq '06123'
|
52
|
+
end
|
53
|
+
it 'is correct' do
|
54
|
+
code = described_class.new('06', normalize: false)
|
55
|
+
expect(code.normalize('0123')).to eq '0123'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#split' do
|
60
|
+
it 'is correct' do
|
61
|
+
code = described_class.new('0')
|
62
|
+
expect(code.split('0123')).to eq [code, '0123']
|
63
|
+
end
|
64
|
+
it 'is correct' do
|
65
|
+
code = described_class.new('0', split: true)
|
66
|
+
expect(code.split('0123')).to eq [code, '123']
|
67
|
+
end
|
68
|
+
it 'is correct' do
|
69
|
+
code = described_class.new('0', split: false)
|
70
|
+
expect(code.split('0123')).to eq [code, '0123']
|
71
|
+
end
|
72
|
+
it 'is correct' do
|
73
|
+
code = described_class.new('06')
|
74
|
+
expect(code.split('06123')).to eq [code, '06123']
|
75
|
+
end
|
76
|
+
it 'is correct' do
|
77
|
+
code = described_class.new('06', split: true)
|
78
|
+
expect(code.split('06123')).to eq [code, '123']
|
79
|
+
end
|
80
|
+
it 'is correct' do
|
81
|
+
code = described_class.new('06', split: false)
|
82
|
+
expect(code.split('06123')).to eq [code, '06123']
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phony
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.19.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Hanke
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: 'Fast international phone number (E164 standard) normalizing, splitting
|
14
14
|
and formatting. Lots of formatting options: International (+.., 00..), national
|
@@ -93,13 +93,14 @@ files:
|
|
93
93
|
- spec/lib/phony/national_splitters/none_spec.rb
|
94
94
|
- spec/lib/phony/national_splitters/regex_spec.rb
|
95
95
|
- spec/lib/phony/national_splitters/variable_spec.rb
|
96
|
+
- spec/lib/phony/trunk_code_spec.rb
|
96
97
|
- spec/lib/phony/vanity_spec.rb
|
97
98
|
- spec/lib/phony_spec.rb
|
98
|
-
homepage:
|
99
|
+
homepage: https://github.com/floere/phony
|
99
100
|
licenses:
|
100
101
|
- MIT
|
101
102
|
metadata: {}
|
102
|
-
post_install_message:
|
103
|
+
post_install_message:
|
103
104
|
rdoc_options: []
|
104
105
|
require_paths:
|
105
106
|
- lib
|
@@ -114,13 +115,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
115
|
- !ruby/object:Gem::Version
|
115
116
|
version: '0'
|
116
117
|
requirements: []
|
117
|
-
rubygems_version: 3.
|
118
|
-
signing_key:
|
118
|
+
rubygems_version: 3.1.6
|
119
|
+
signing_key:
|
119
120
|
specification_version: 4
|
120
121
|
summary: Fast international phone number (E164 standard) normalizing, splitting and
|
121
122
|
formatting.
|
122
123
|
test_files:
|
123
124
|
- spec/lib/phony_spec.rb
|
125
|
+
- spec/lib/phony/trunk_code_spec.rb
|
124
126
|
- spec/lib/phony/country_spec.rb
|
125
127
|
- spec/lib/phony/national_code_spec.rb
|
126
128
|
- spec/lib/phony/countries_spec.rb
|