phony 2.20.1 → 2.20.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/phony/countries/italy.rb +10 -1
- data/lib/phony/countries.rb +9 -1
- data/spec/functional/config_spec.rb +5 -5
- data/spec/functional/plausibility_spec.rb +9 -3
- data/spec/lib/phony/countries_spec.rb +2 -2
- data/spec/lib/phony/country_codes_spec.rb +61 -59
- data/spec/lib/phony/country_spec.rb +13 -13
- data/spec/lib/phony/dsl_spec.rb +6 -2
- data/spec/lib/phony/local_splitters/regex_spec.rb +12 -15
- data/spec/lib/phony/national_code_spec.rb +15 -45
- data/spec/lib/phony/national_splitters/fixed_spec.rb +12 -16
- data/spec/lib/phony/national_splitters/none_spec.rb +3 -3
- data/spec/lib/phony/national_splitters/variable_spec.rb +9 -13
- data/spec/lib/phony/vanity_spec.rb +4 -4
- metadata +15 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27443f0af2d18a25a1b9056a1a09e77dffd8e8669346d974a3970cdfe9931ee4
|
4
|
+
data.tar.gz: b5d22d65bb38fcb66b8f966716e5a5ee582d272a53b418b3ed20070ce90a74c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ee83977f8d9f5b8ccbcbbea65976ff20456fd35f4adca206e91b9efe4838cf80bef3a15b8cd837e093f4cfedca43a757e7ecd2c941abae9d08c0d54f217c930
|
7
|
+
data.tar.gz: 30760e746ca05cadc07b41e404507537a18f516938b9701a18ecedd6a56d14f9f1eb39eee754d8121679e7217514be356f250292a7d7a9bad7a89efcc98168c4
|
@@ -256,7 +256,8 @@ ndcs_3digit = [
|
|
256
256
|
# but this was not frozen so easily.
|
257
257
|
mobile = %w(300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399)
|
258
258
|
|
259
|
-
|
259
|
+
# Not exhaustive.
|
260
|
+
service = [
|
260
261
|
'112',
|
261
262
|
'113',
|
262
263
|
'115',
|
@@ -268,11 +269,19 @@ service = [ # Not exhaustive.
|
|
268
269
|
'1530'
|
269
270
|
]
|
270
271
|
|
272
|
+
# Not exhaustive. Unused below - just for info purposes.
|
273
|
+
free_of_charge_services = [
|
274
|
+
'800',
|
275
|
+
'803'
|
276
|
+
]
|
277
|
+
|
271
278
|
Phony.define do
|
272
279
|
# Note: The 0 does not count towards NDC number length.
|
273
280
|
country '39', trunk('', normalize: false) |
|
274
281
|
one_of(*service) >> split(3,3) |
|
275
282
|
one_of(*mobile) >> split(3,4,-1..1) |
|
283
|
+
match(/^(800)\d{6}$/) >> split(6) | # 3-6, Special handling for 800 numbers.
|
284
|
+
match(/^(803)\d{3}$/) >> split(3) | # 3-3, Special handling for 803 numbers.
|
276
285
|
one_of(*ndcs_1digit) >> matched_split(
|
277
286
|
/\A\d{5}\z/ => [5],
|
278
287
|
/\A\d{6}\z/ => [4,2],
|
data/lib/phony/countries.rb
CHANGED
@@ -363,7 +363,15 @@ Phony.define do
|
|
363
363
|
trunk('', :normalize => false) |
|
364
364
|
fixed(2) >> split(2,2,2,2)
|
365
365
|
|
366
|
-
|
366
|
+
# Burkina Faso
|
367
|
+
# http://www.wtng.info/wtng-226-bf.html
|
368
|
+
# https://en.wikipedia.org/wiki/Telephone_numbers_in_Burkina_Faso
|
369
|
+
#
|
370
|
+
# There is no trunk code for this country and several of the mobile prefixes start with 0
|
371
|
+
country '226',
|
372
|
+
trunk('', normalize: false) |
|
373
|
+
none >> split(2,2,2,2)
|
374
|
+
|
367
375
|
country '227', none >> split(4,4) # Niger http://www.wtng.info/wtng-227-ne.html
|
368
376
|
country '228', none >> split(4,4) # Togolese Republic http://www.wtng.info/wtng-228-tg.html
|
369
377
|
country '229', none >> split(4,4) # Benin http://www.itu.int/oth/T0202000017/en
|
@@ -18,27 +18,27 @@ describe 'Phony::Config' do
|
|
18
18
|
it 'does not fail when loading all' do
|
19
19
|
Phony::Config.load
|
20
20
|
|
21
|
-
Phony.split('15551115511').
|
21
|
+
expect(Phony.split('15551115511')).to eq ['1', '555', '111', '5511']
|
22
22
|
end
|
23
23
|
it 'raises when a CC is used that has not been loaded.' do
|
24
24
|
Phony::Config.load('41')
|
25
25
|
|
26
|
-
expect { Phony.split('15551115511') }.to raise_error
|
26
|
+
expect { Phony.split('15551115511') }.to raise_error(Phony::SplittingError)
|
27
27
|
end
|
28
28
|
it 'raises when a CC is used that has not been loaded.' do
|
29
29
|
Phony::Config.load(only: ['41'])
|
30
30
|
|
31
|
-
expect { Phony.split('15551115511') }.to raise_error
|
31
|
+
expect { Phony.split('15551115511') }.to raise_error(Phony::SplittingError)
|
32
32
|
end
|
33
33
|
it 'raises when a CC is used that has not been loaded.' do
|
34
34
|
Phony::Config.load(except: ['1'])
|
35
35
|
|
36
|
-
expect { Phony.split('15551115511') }.to raise_error
|
36
|
+
expect { Phony.split('15551115511') }.to raise_error(Phony::SplittingError)
|
37
37
|
end
|
38
38
|
it 'does not raise when a CC is used that has been loaded.' do
|
39
39
|
Phony::Config.load(except: ['41'])
|
40
40
|
|
41
|
-
Phony.split('15551115511').
|
41
|
+
expect(Phony.split('15551115511')).to eq ['1', '555', '111', '5511']
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -25,11 +25,11 @@ describe 'plausibility' do
|
|
25
25
|
incorrect = [shortest.sub(/\d\s*\z/, '')] # , longest + '0']
|
26
26
|
|
27
27
|
correct.each do |value|
|
28
|
-
Phony.plausible?(value).
|
28
|
+
expect(Phony.plausible?(value)).to be_truthy,
|
29
29
|
"It should validate #{value}, but does not."
|
30
30
|
end
|
31
31
|
incorrect.each do |value|
|
32
|
-
Phony.plausible?(value).
|
32
|
+
expect(Phony.plausible?(value)).to be_falsey,
|
33
33
|
"It should not validate #{value}, but does."
|
34
34
|
end
|
35
35
|
end
|
@@ -38,7 +38,7 @@ describe 'plausibility' do
|
|
38
38
|
invalid = [*sample]
|
39
39
|
|
40
40
|
invalid.each do |value|
|
41
|
-
Phony.plausible?(value).
|
41
|
+
expect(Phony.plausible?(value)).to be_falsey,
|
42
42
|
"It should not validate #{value}, but does."
|
43
43
|
end
|
44
44
|
end
|
@@ -621,6 +621,12 @@ describe 'plausibility' do
|
|
621
621
|
Phony.plausible?('+39 06 4991').should be_falsy
|
622
622
|
Phony.plausible?('+39 06 49911').should be_truthy
|
623
623
|
Phony.plausible?('+39 06 499112').should be_truthy
|
624
|
+
|
625
|
+
Phony.plausible?('+39 800 081631').should be_truthy
|
626
|
+
Phony.plausible?('+39 800 0816311').should be_falsy
|
627
|
+
|
628
|
+
Phony.plausible?('+39 803 08163').should be_falsy
|
629
|
+
Phony.plausible?('+39 803 081').should be_truthy
|
624
630
|
end
|
625
631
|
|
626
632
|
it 'is correct for Russia' do
|
@@ -5,7 +5,7 @@ require 'spec_helper'
|
|
5
5
|
describe 'country descriptions' do
|
6
6
|
|
7
7
|
def self.it_splits number, expected
|
8
|
-
it { Phony.split(number).
|
8
|
+
it { expect(Phony.split(number)).to eq expected }
|
9
9
|
end
|
10
10
|
|
11
11
|
describe 'regression' do
|
@@ -871,7 +871,7 @@ describe 'country descriptions' do
|
|
871
871
|
it_splits '6737932744', %w(673 7 932 744)
|
872
872
|
end
|
873
873
|
describe 'Burkina Faso' do
|
874
|
-
it_splits '22667839323', ['226', false, '
|
874
|
+
it_splits '22667839323', ['226', false, '67', '83', '93', '23']
|
875
875
|
end
|
876
876
|
describe 'Burundi' do
|
877
877
|
it_splits '25712345678', ['257', false, '1234', '5678']
|
@@ -15,207 +15,209 @@ describe Phony::CountryCodes do
|
|
15
15
|
describe 'ccc handling' do
|
16
16
|
it 'splits a ccc correctly' do
|
17
17
|
cc, ndc, *local = countries.split('1868')
|
18
|
-
|
19
|
-
|
18
|
+
|
19
|
+
expect(cc).to eq '1'
|
20
|
+
expect(ndc).to eq '868'
|
20
21
|
end
|
21
22
|
it 'splits a ccc correctly' do
|
22
23
|
cc, ndc, *local = countries.split('1868')
|
23
|
-
|
24
|
-
|
24
|
+
|
25
|
+
expect(cc).to eq '1'
|
26
|
+
expect(ndc).to eq '868'
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
28
30
|
describe '#[]' do
|
29
31
|
it 'returns a country' do
|
30
|
-
countries['41'].class.
|
32
|
+
expect(countries['41'].class).to eq Phony::Country
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
34
36
|
describe '#country_for' do
|
35
37
|
it 'returns a country' do
|
36
|
-
countries.send(:country_for, '41').class.
|
38
|
+
expect(countries.send(:country_for, '41').class).to eq Phony::Country
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
40
42
|
describe '#countrify' do
|
41
43
|
it 'returns a country' do
|
42
|
-
countries.send(:countrify, '441231212', '41').
|
44
|
+
expect(countries.send(:countrify, '441231212', '41')).to eq '41441231212'
|
43
45
|
end
|
44
46
|
end
|
45
47
|
describe '#countrify!' do
|
46
48
|
it 'in-place replaces the number' do
|
47
49
|
number = '441231212'
|
48
|
-
countries.send(:countrify!, number, '41').
|
50
|
+
expect(countries.send(:countrify!, number, '41')).to eq number
|
49
51
|
|
50
|
-
number.
|
52
|
+
expect(number).to eq '41441231212'
|
51
53
|
end
|
52
54
|
end
|
53
55
|
|
54
56
|
describe '#vanity?' do
|
55
57
|
it 'returns true if so' do
|
56
|
-
countries.vanity?('1800HELLOES').
|
58
|
+
expect(countries.vanity?('1800HELLOES')).to eq true
|
57
59
|
end
|
58
60
|
it 'returns false if not' do
|
59
|
-
countries.vanity?('18001234567').
|
61
|
+
expect(countries.vanity?('18001234567')).to eq false
|
60
62
|
end
|
61
63
|
end
|
62
64
|
|
63
65
|
describe 'normalize' do
|
64
66
|
it 'normalizes correctly' do
|
65
|
-
countries.normalize('0041-44-364-35-32').
|
67
|
+
expect(countries.normalize('0041-44-364-35-32')).to eq '41443643532'
|
66
68
|
end
|
67
69
|
it 'normalizes correctly with CC option' do
|
68
|
-
countries.normalize('044-364-35-32', cc: '41').
|
70
|
+
expect(countries.normalize('044-364-35-32', cc: '41')).to eq '41443643532'
|
69
71
|
end
|
70
72
|
|
71
73
|
context 'specific countries' do
|
72
74
|
it 'handles Congo correctly' do
|
73
|
-
countries.normalize('+242 0571 73992').
|
74
|
-
countries.normalize('+242 2221 15932').
|
75
|
+
expect(countries.normalize('+242 0571 73992')).to eq '242057173992'
|
76
|
+
expect(countries.normalize('+242 2221 15932')).to eq '242222115932'
|
75
77
|
end
|
76
78
|
end
|
77
79
|
end
|
78
80
|
|
79
81
|
describe 'formatted' do
|
80
82
|
it 'formats correctly' do
|
81
|
-
countries.formatted('41443643532', :format => :international, :spaces => :-).
|
83
|
+
expect(countries.formatted('41443643532', :format => :international, :spaces => :-)).to eq '+41-44-364-35-32'
|
82
84
|
end
|
83
85
|
it 'formats correctly' do
|
84
|
-
countries.formatted('41443643532', :format => :international_relative, :spaces => :-).
|
86
|
+
expect(countries.formatted('41443643532', :format => :international_relative, :spaces => :-)).to eq '0041-44-364-35-32'
|
85
87
|
end
|
86
88
|
it 'formats correctly' do
|
87
|
-
countries.formatted('41443643532', :format => :national, :spaces => :-).
|
89
|
+
expect(countries.formatted('41443643532', :format => :national, :spaces => :-)).to eq '044-364-35-32'
|
88
90
|
end
|
89
91
|
context 'specific' do
|
90
92
|
it 'formats Ireland correctly' do
|
91
|
-
countries.formatted("3533451234", :format => :national).
|
93
|
+
expect(countries.formatted("3533451234", :format => :national)).to eq '0345 1234'
|
92
94
|
end
|
93
95
|
it 'formats Ireland correctly' do
|
94
|
-
countries.formatted("353411231234", :format => :national).
|
96
|
+
expect(countries.formatted("353411231234", :format => :national)).to eq '041 123 1234'
|
95
97
|
end
|
96
98
|
it 'formats Spain correctly' do
|
97
|
-
countries.formatted("34123456789", :format => :national).
|
99
|
+
expect(countries.formatted("34123456789", :format => :national)).to eq '123 456 789'
|
98
100
|
end
|
99
101
|
it 'formats Cambodia correctly' do
|
100
|
-
countries.formatted('85512239123', :format => :national).
|
102
|
+
expect(countries.formatted('85512239123', :format => :national)).to eq '012 239 123'
|
101
103
|
end
|
102
104
|
it 'formats the US correctly' do
|
103
|
-
countries.formatted('18005551212', :format => :national, :spaces => :-).
|
105
|
+
expect(countries.formatted('18005551212', :format => :national, :spaces => :-)).to eq '(800)-555-1212'
|
104
106
|
end
|
105
107
|
it 'formats the US correctly' do
|
106
|
-
countries.formatted('18005551212', :format => :national, :spaces => :-).
|
108
|
+
expect(countries.formatted('18005551212', :format => :national, :spaces => :-)).to eq '(800)-555-1212'
|
107
109
|
end
|
108
110
|
end
|
109
111
|
context 'default' do
|
110
112
|
it "should format swiss numbers" do
|
111
|
-
countries.formatted('41443643532').
|
113
|
+
expect(countries.formatted('41443643532')).to eq '+41 44 364 35 32'
|
112
114
|
end
|
113
115
|
it "should format swiss service numbers" do
|
114
|
-
countries.formatted('41800112233').
|
116
|
+
expect(countries.formatted('41800112233')).to eq '+41 800 112 233'
|
115
117
|
end
|
116
118
|
it "should format austrian numbers" do
|
117
|
-
countries.formatted('43198110').
|
119
|
+
expect(countries.formatted('43198110')).to eq '+43 1 98110'
|
118
120
|
end
|
119
121
|
it "should format american numbers" do
|
120
|
-
countries.formatted('18705551122').
|
122
|
+
expect(countries.formatted('18705551122')).to eq '+1 (870) 555-1122'
|
121
123
|
end
|
122
124
|
it "should format irish numbers" do
|
123
|
-
countries.formatted('35311234567').
|
125
|
+
expect(countries.formatted('35311234567')).to eq '+353 1 123 4567'
|
124
126
|
end
|
125
127
|
end
|
126
128
|
describe "international" do
|
127
129
|
it "should format north american numbers" do
|
128
|
-
countries.formatted('18091231234', :format => :international).
|
130
|
+
expect(countries.formatted('18091231234', :format => :international)).to eq '+1 (809) 123-1234'
|
129
131
|
end
|
130
132
|
it "should format austrian numbers" do
|
131
|
-
countries.formatted('43198110', :format => :international).
|
133
|
+
expect(countries.formatted('43198110', :format => :international)).to eq '+43 1 98110'
|
132
134
|
end
|
133
135
|
it "should format austrian numbers" do
|
134
|
-
countries.formatted('43198110', :format => :international_absolute).
|
136
|
+
expect(countries.formatted('43198110', :format => :international_absolute)).to eq '+43 1 98110'
|
135
137
|
end
|
136
138
|
it "should format french numbers" do
|
137
|
-
countries.formatted('33142278186', :format => :+).
|
139
|
+
expect(countries.formatted('33142278186', :format => :+)).to eq '+33 1 42 27 81 86'
|
138
140
|
end
|
139
141
|
it "should format austrian numbers" do
|
140
|
-
countries.formatted('43198110', :format => :international_relative).
|
142
|
+
expect(countries.formatted('43198110', :format => :international_relative)).to eq '0043 1 98110'
|
141
143
|
end
|
142
144
|
it 'should format liechtensteiner numbers' do
|
143
|
-
countries.formatted('4233841148', :format => :international_relative).
|
145
|
+
expect(countries.formatted('4233841148', :format => :international_relative)).to eq '00423 384 11 48'
|
144
146
|
end
|
145
147
|
it "should format irish numbers" do
|
146
|
-
countries.formatted('35311234567', :format => :international).
|
148
|
+
expect(countries.formatted('35311234567', :format => :international)).to eq '+353 1 123 4567'
|
147
149
|
end
|
148
150
|
it "should format luxembourgian numbers" do
|
149
|
-
countries.formatted('352222809', :format => :international).
|
151
|
+
expect(countries.formatted('352222809', :format => :international)).to eq '+352 22 28 09'
|
150
152
|
end
|
151
153
|
it "should format luxembourgian 4-digit ndc numbers" do
|
152
|
-
countries.formatted('35226222809', :format => :international).
|
154
|
+
expect(countries.formatted('35226222809', :format => :international)).to eq '+352 2622 28 09'
|
153
155
|
end
|
154
156
|
it "should format luxembourgian mobile numbers" do
|
155
|
-
countries.formatted('352621123456', :format => :international).
|
157
|
+
expect(countries.formatted('352621123456', :format => :international)).to eq '+352 621 123 456'
|
156
158
|
end
|
157
159
|
it "should format luxembourgian city numbers" do
|
158
|
-
countries.formatted('3524123456', :format => :international).
|
160
|
+
expect(countries.formatted('3524123456', :format => :international)).to eq '+352 41 23 45 6'
|
159
161
|
end
|
160
162
|
it "should format luxembourgian machine to machine numbers" do
|
161
|
-
countries.formatted('352602112345678', :format => :international).
|
163
|
+
expect(countries.formatted('352602112345678', :format => :international)).to eq '+352 6021 12 34 56 78'
|
162
164
|
end
|
163
165
|
it "should format luxembourgian numbers" do
|
164
|
-
countries.formatted('352370431', :format => :international).
|
166
|
+
expect(countries.formatted('352370431', :format => :international)).to eq '+352 37 04 31'
|
165
167
|
end
|
166
168
|
it "should format luxembourgian numbers" do
|
167
|
-
countries.formatted('35227855', :format => :international).
|
169
|
+
expect(countries.formatted('35227855', :format => :international)).to eq '+352 27 85 5'
|
168
170
|
end
|
169
171
|
it "should format nigerian lagosian numbers" do
|
170
|
-
countries.formatted('23414480000', :format => :international).
|
172
|
+
expect(countries.formatted('23414480000', :format => :international)).to eq '+234 1 448 0000'
|
171
173
|
end
|
172
174
|
it "should format nigerian beninese numbers" do
|
173
|
-
countries.formatted('23452123456', :format => :international).
|
175
|
+
expect(countries.formatted('23452123456', :format => :international)).to eq '+234 52 123 456'
|
174
176
|
end
|
175
177
|
it "should format nigerian mobile numbers" do
|
176
|
-
countries.formatted('2347061234567', :format => :international).
|
178
|
+
expect(countries.formatted('2347061234567', :format => :international)).to eq '+234 706 123 4567'
|
177
179
|
end
|
178
180
|
context 'with no spaces' do
|
179
181
|
it "should format north american numbers" do
|
180
|
-
Phony.formatted('18091231234', :format => :international, :spaces => '').
|
182
|
+
expect(Phony.formatted('18091231234', :format => :international, :spaces => '')).to eq '+1(809)123-1234'
|
181
183
|
end
|
182
184
|
it "should format austrian numbers" do
|
183
|
-
Phony.formatted('43198110', :format => :international, :spaces => '').
|
185
|
+
expect(Phony.formatted('43198110', :format => :international, :spaces => '')).to eq '+43198110'
|
184
186
|
end
|
185
187
|
it "should format austrian numbers" do
|
186
|
-
Phony.formatted('43198110', :format => :international_absolute, :spaces => '').
|
188
|
+
expect(Phony.formatted('43198110', :format => :international_absolute, :spaces => '')).to eq '+43198110'
|
187
189
|
end
|
188
190
|
it "should format french numbers" do
|
189
|
-
Phony.formatted('33142278186', :format => :+, :spaces => '').
|
191
|
+
expect(Phony.formatted('33142278186', :format => :+, :spaces => '')).to eq '+33142278186'
|
190
192
|
end
|
191
193
|
it "should format austrian numbers" do
|
192
|
-
Phony.formatted('43198110', :format => :international_relative, :spaces => '').
|
194
|
+
expect(Phony.formatted('43198110', :format => :international_relative, :spaces => '')).to eq '0043198110'
|
193
195
|
end
|
194
196
|
it 'should format liechtensteiner numbers' do
|
195
|
-
Phony.formatted('4233841148', :format => :international_relative, :spaces => '').
|
197
|
+
expect(Phony.formatted('4233841148', :format => :international_relative, :spaces => '')).to eq '004233841148'
|
196
198
|
end
|
197
199
|
end
|
198
200
|
context 'with special spaces' do
|
199
201
|
it "should format swiss numbers" do
|
200
|
-
Phony.formatted('41443643532', :format => :international).
|
202
|
+
expect(Phony.formatted('41443643532', :format => :international)).to eq '+41 44 364 35 32'
|
201
203
|
end
|
202
204
|
it "should format north american numbers" do
|
203
|
-
Phony.formatted('18091231234', :format => :international, :spaces => :-).
|
205
|
+
expect(Phony.formatted('18091231234', :format => :international, :spaces => :-)).to eq '+1-(809)-123-1234'
|
204
206
|
end
|
205
207
|
it "should format austrian numbers" do
|
206
|
-
Phony.formatted('43198110', :format => :international, :spaces => :-).
|
208
|
+
expect(Phony.formatted('43198110', :format => :international, :spaces => :-)).to eq '+43-1-98110'
|
207
209
|
end
|
208
210
|
it "should format austrian numbers" do
|
209
|
-
Phony.formatted('43198110', :format => :international_absolute, :spaces => :-).
|
211
|
+
expect(Phony.formatted('43198110', :format => :international_absolute, :spaces => :-)).to eq '+43-1-98110'
|
210
212
|
end
|
211
213
|
it "should format french numbers" do
|
212
|
-
Phony.formatted('33142278186', :format => :+, :spaces => :-).
|
214
|
+
expect(Phony.formatted('33142278186', :format => :+, :spaces => :-)).to eq '+33-1-42-27-81-86'
|
213
215
|
end
|
214
216
|
it "should format austrian numbers" do
|
215
|
-
Phony.formatted('43198110', :format => :international_relative, :spaces => :-).
|
217
|
+
expect(Phony.formatted('43198110', :format => :international_relative, :spaces => :-)).to eq '0043-1-98110'
|
216
218
|
end
|
217
219
|
it 'should format liechtensteiner numbers' do
|
218
|
-
Phony.formatted('4233841148', :format => :international_relative, :spaces => :-).
|
220
|
+
expect(Phony.formatted('4233841148', :format => :international_relative, :spaces => :-)).to eq '00423-384-11-48'
|
219
221
|
end
|
220
222
|
|
221
223
|
end
|
@@ -12,12 +12,12 @@ describe Phony::Country do
|
|
12
12
|
end
|
13
13
|
describe '#clean' do
|
14
14
|
it 'cleans the number' do
|
15
|
-
country.clean('+41-44-123-12-12').
|
15
|
+
expect(country.clean('+41-44-123-12-12')).to eq '41441231212'
|
16
16
|
end
|
17
17
|
end
|
18
18
|
describe '#vanity_to_number' do
|
19
19
|
it 'turns the vanity number into a number' do
|
20
|
-
country.vanity_to_number('1-800-HELLO').
|
20
|
+
expect(country.vanity_to_number('1-800-HELLO')).to eq '1-800-43556'
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -32,27 +32,27 @@ describe Phony::Country do
|
|
32
32
|
described_class.new national_code
|
33
33
|
end
|
34
34
|
it 'splits correctly' do
|
35
|
-
country.split('112').
|
35
|
+
expect(country.split('112')).to eq [nil, false, '112']
|
36
36
|
end
|
37
37
|
end
|
38
38
|
describe 'San Marino' do
|
39
39
|
it 'normalizes correctly' do
|
40
|
-
Phony.normalize('+3780549903549').
|
40
|
+
expect(Phony.normalize('+3780549903549')).to eq '3780549903549'
|
41
41
|
end
|
42
42
|
xit 'automatically adds the sole NC' do
|
43
|
-
Phony.normalize('+378903549').
|
43
|
+
expect(Phony.normalize('+378903549')).to eq '3780549903549'
|
44
44
|
end
|
45
45
|
end
|
46
46
|
describe 'Japan' do
|
47
47
|
it 'normalizes correctly' do
|
48
|
-
Phony.normalize('+81-03-1234-5634').
|
49
|
-
Phony.normalize('03-1234-5634', cc: '81').
|
48
|
+
expect(Phony.normalize('+81-03-1234-5634')).to eq '81312345634'
|
49
|
+
expect(Phony.normalize('03-1234-5634', cc: '81')).to eq '81312345634'
|
50
50
|
end
|
51
51
|
it 'formats correctly' do
|
52
|
-
Phony.format('81312345634').
|
52
|
+
expect(Phony.format('81312345634')).to eq '+81-3-1234-5634'
|
53
53
|
end
|
54
54
|
it 'splits correctly' do
|
55
|
-
Phony.split('81312345634').
|
55
|
+
expect(Phony.split('81312345634')).to eq %w(81 3 1234 5634)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
@@ -68,12 +68,12 @@ describe Phony::Country do
|
|
68
68
|
|
69
69
|
describe "split" do
|
70
70
|
it "should handle ZH" do
|
71
|
-
country.split('443643532').
|
71
|
+
expect(country.split('443643532')).to eq [nil, '44', '364', '35', '32']
|
72
72
|
end
|
73
73
|
end
|
74
74
|
describe 'normalize' do
|
75
75
|
it "should handle ZH" do
|
76
|
-
country.normalize('0443643532').
|
76
|
+
expect(country.normalize('0443643532')).to eq '443643532'
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
@@ -93,10 +93,10 @@ describe Phony::Country do
|
|
93
93
|
|
94
94
|
describe "split" do
|
95
95
|
it "should handle ZH" do
|
96
|
-
country.split('443643532').
|
96
|
+
expect(country.split('443643532')).to eq [nil, '44', '364', '35', '32']
|
97
97
|
end
|
98
98
|
it "should handle 800" do
|
99
|
-
country.split('800333666').
|
99
|
+
expect(country.split('800333666')).to eq [nil, '800', '333', '666']
|
100
100
|
end
|
101
101
|
end
|
102
102
|
end
|
data/spec/lib/phony/dsl_spec.rb
CHANGED
@@ -7,9 +7,13 @@ describe Phony::DSL do
|
|
7
7
|
let(:dsl) { described_class.new }
|
8
8
|
|
9
9
|
it 'has a todo' do
|
10
|
+
result = nil
|
11
|
+
|
10
12
|
Phony.define do
|
11
|
-
todo.split("123456789012345")
|
13
|
+
result = todo.split("123456789012345")
|
12
14
|
end
|
15
|
+
|
16
|
+
expect(result).to eq [nil, false, '123456789012345']
|
13
17
|
end
|
14
18
|
|
15
19
|
describe 'match' do
|
@@ -17,7 +21,7 @@ describe Phony::DSL do
|
|
17
21
|
expect { dsl.match(/123/) }.to raise_error("Regexp /123/ needs a group in it that defines which digits belong to the NDC.")
|
18
22
|
end
|
19
23
|
it 'should return a Phony::NationalSplitters::Regex' do
|
20
|
-
dsl.match(/(123)/).class.name.
|
24
|
+
expect(dsl.match(/(123)/).class.name).to eq Phony::NationalSplitters::Regex.name
|
21
25
|
end
|
22
26
|
end
|
23
27
|
|
@@ -16,40 +16,37 @@ describe Phony::LocalSplitters::Regex do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
describe 'split' do
|
19
|
-
|
20
|
-
|
21
|
-
#
|
22
|
-
@splitter = described_class.instance_for(/^[489].*$/ => [3,2,3], :fallback => [2,2,2,2])
|
23
|
-
end
|
19
|
+
# Norway.
|
20
|
+
let(:splitter) { described_class.instance_for(/^[489].*$/ => [3,2,3], :fallback => [2,2,2,2]) }
|
24
21
|
it 'splits a number correctly' do
|
25
|
-
|
22
|
+
expect(splitter.split('21234567')).to eq ['21','23','45','67']
|
26
23
|
end
|
27
24
|
it 'splits a number correctly' do
|
28
|
-
|
25
|
+
expect(splitter.split('31234567')).to eq ['31','23','45','67']
|
29
26
|
end
|
30
27
|
it 'splits a number correctly' do
|
31
|
-
|
28
|
+
expect(splitter.split('41234567')).to eq ['412','34','567']
|
32
29
|
end
|
33
30
|
it 'splits a number correctly' do
|
34
|
-
|
31
|
+
expect(splitter.split('51234567')).to eq ['51','23','45','67']
|
35
32
|
end
|
36
33
|
it 'splits a number correctly' do
|
37
|
-
|
34
|
+
expect(splitter.split('61234567')).to eq ['61','23','45','67']
|
38
35
|
end
|
39
36
|
it 'splits a number correctly' do
|
40
|
-
|
37
|
+
expect(splitter.split('71234567')).to eq ['71','23','45','67']
|
41
38
|
end
|
42
39
|
it 'splits a number correctly' do
|
43
|
-
|
40
|
+
expect(splitter.split('81234567')).to eq ['812','34','567']
|
44
41
|
end
|
45
42
|
it 'splits a number correctly' do
|
46
|
-
|
43
|
+
expect(splitter.split('91234567')).to eq ['912','34','567']
|
47
44
|
end
|
48
45
|
it 'splits it fast' do
|
49
|
-
performance_of {
|
46
|
+
expect(performance_of { splitter.split('21234567') }).to be < 0.00005
|
50
47
|
end
|
51
48
|
it 'splits it fast' do
|
52
|
-
performance_of {
|
49
|
+
expect(performance_of { splitter.split('91234567') }).to be < 0.00004
|
53
50
|
end
|
54
51
|
end
|
55
52
|
|
@@ -5,87 +5,57 @@ describe Phony::NationalCode do
|
|
5
5
|
describe 'split' do
|
6
6
|
context 'regression' do
|
7
7
|
describe 'iceland' do
|
8
|
-
|
8
|
+
let(:national) do
|
9
9
|
national_splitter = Phony::NationalSplitters::None.instance_for
|
10
10
|
local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 4]
|
11
11
|
|
12
|
-
|
12
|
+
Phony::NationalCode.new national_splitter, local_splitter
|
13
13
|
end
|
14
14
|
it 'splits correctly' do
|
15
|
-
|
15
|
+
expect(national.split('112')).to eq [nil, false, '112']
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
19
19
|
context 'with fixed ndc (Swiss)' do
|
20
|
-
|
20
|
+
let(:national) do
|
21
21
|
national_splitter = Phony::NationalSplitters::Fixed.instance_for 2
|
22
22
|
local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 2, 2]
|
23
23
|
|
24
|
-
|
24
|
+
Phony::NationalCode.new national_splitter, local_splitter
|
25
25
|
end
|
26
26
|
it 'splits correctly' do
|
27
|
-
|
27
|
+
expect(national.split('443643532')).to eq [nil, '44', '364', '35', '32']
|
28
28
|
end
|
29
29
|
it 'splits correctly' do
|
30
|
-
|
30
|
+
expect(national.split('44364353')).to eq [nil, '44', '364', '35', '3']
|
31
31
|
end
|
32
32
|
it 'normalizes correctly' do
|
33
|
-
|
33
|
+
expect(national.normalize('044364353')).to eq '44364353'
|
34
34
|
end
|
35
35
|
it 'normalizes correctly' do
|
36
|
-
|
36
|
+
expect(national.normalize('44364353')).to eq '44364353'
|
37
37
|
end
|
38
38
|
end
|
39
39
|
context 'with fixed ndc (French)' do
|
40
|
-
|
40
|
+
let(:national) do
|
41
41
|
national_splitter = Phony::NationalSplitters::Fixed.instance_for 1
|
42
42
|
local_splitter = Phony::LocalSplitters::Fixed.instance_for [2, 2, 2, 2]
|
43
43
|
|
44
|
-
|
44
|
+
Phony::NationalCode.new national_splitter, local_splitter
|
45
45
|
end
|
46
46
|
it 'splits correctly' do
|
47
|
-
|
47
|
+
expect(national.split('142278186')).to eq [nil, '1', '42', '27', '81', '86']
|
48
48
|
end
|
49
49
|
it 'splits correctly' do
|
50
|
-
|
50
|
+
expect(national.split('14227818')).to eq [nil, '1', '42', '27', '81', '8']
|
51
51
|
end
|
52
52
|
it 'normalizes correctly' do
|
53
|
-
|
53
|
+
expect(national.normalize('0142278186')).to eq '142278186'
|
54
54
|
end
|
55
55
|
it 'normalizes correctly' do
|
56
|
-
|
56
|
+
expect(national.normalize('142278186')).to eq '142278186'
|
57
57
|
end
|
58
58
|
end
|
59
|
-
# context 'normalizing' do
|
60
|
-
# context 'false' do
|
61
|
-
# before(:each) do
|
62
|
-
# @national = Phony::NationalCode.new nil, nil, false
|
63
|
-
# end
|
64
|
-
# it 'normalizes an italian case correctly' do
|
65
|
-
# @national.normalize('0909709511').should == '0909709511'
|
66
|
-
# end
|
67
|
-
# end
|
68
|
-
# context 'true' do
|
69
|
-
# before(:each) do
|
70
|
-
# national_splitter = Phony::NationalSplitters::Fixed.instance_for 2
|
71
|
-
# local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 2, 2]
|
72
|
-
# @national = Phony::NationalCode.new national_splitter, local_splitter, true
|
73
|
-
# end
|
74
|
-
# it 'normalizes a swiss case correctly' do
|
75
|
-
# @national.normalize('044364353').should == '44364353'
|
76
|
-
# end
|
77
|
-
# end
|
78
|
-
# context 'nil (true)' do
|
79
|
-
# before(:each) do
|
80
|
-
# national_splitter = Phony::NationalSplitters::Fixed.instance_for 2
|
81
|
-
# local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 2, 2]
|
82
|
-
# @national = Phony::NationalCode.new national_splitter, local_splitter, nil
|
83
|
-
# end
|
84
|
-
# it 'normalizes a swiss case correctly' do
|
85
|
-
# @national.normalize('044364353').should == '44364353'
|
86
|
-
# end
|
87
|
-
# end
|
88
|
-
# end
|
89
59
|
end
|
90
60
|
|
91
61
|
end
|
@@ -4,45 +4,41 @@ describe Phony::NationalSplitters::Fixed do
|
|
4
4
|
|
5
5
|
describe 'instance_for' do
|
6
6
|
it 'caches' do
|
7
|
-
Phony::NationalSplitters::Fixed.instance_for(3).
|
7
|
+
expect(Phony::NationalSplitters::Fixed.instance_for(3)).to eq Phony::NationalSplitters::Fixed.instance_for(3)
|
8
8
|
end
|
9
9
|
it 'caches correctly' do
|
10
|
-
Phony::NationalSplitters::Fixed.instance_for(1).
|
10
|
+
expect(Phony::NationalSplitters::Fixed.instance_for(1)).to_not eq Phony::NationalSplitters::Fixed.instance_for(2)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
describe 'split' do
|
15
|
-
|
16
|
-
@splitter = Phony::NationalSplitters::Fixed.new 2
|
17
|
-
end
|
15
|
+
let(:splitter) { Phony::NationalSplitters::Fixed.new(2) }
|
18
16
|
it 'splits correctly' do
|
19
|
-
|
17
|
+
expect(splitter.split('443643532')).to eq [nil, '44', '3643532']
|
20
18
|
end
|
21
19
|
it 'splits correctly even when the number is too long' do
|
22
|
-
|
20
|
+
expect(splitter.split('44364353211')).to eq [nil, '44', '364353211']
|
23
21
|
end
|
24
22
|
it 'splits correctly even when the number is too short' do
|
25
|
-
|
23
|
+
expect(splitter.split('443')).to eq [nil, '44','3']
|
26
24
|
end
|
27
25
|
it 'has a length of 2' do
|
28
|
-
|
26
|
+
expect(splitter.length).to eq 2
|
29
27
|
end
|
30
28
|
end
|
31
29
|
describe 'split' do
|
32
|
-
|
33
|
-
@splitter = Phony::NationalSplitters::Fixed.new nil
|
34
|
-
end
|
30
|
+
let(:splitter) { Phony::NationalSplitters::Fixed.new(nil) }
|
35
31
|
it 'splits correctly' do
|
36
|
-
|
32
|
+
expect(splitter.split('443643532')).to eq [nil, '443643532']
|
37
33
|
end
|
38
34
|
it 'splits correctly even when the number is too long' do
|
39
|
-
|
35
|
+
expect(splitter.split('44364353211')).to eq [nil, '44364353211']
|
40
36
|
end
|
41
37
|
it 'splits correctly even when the number is too short' do
|
42
|
-
|
38
|
+
expect(splitter.split('443')).to eq [nil, '443']
|
43
39
|
end
|
44
40
|
it 'has a length of nil' do
|
45
|
-
|
41
|
+
expect(splitter.length).to eq nil
|
46
42
|
end
|
47
43
|
end
|
48
44
|
|
@@ -4,7 +4,7 @@ describe Phony::NationalSplitters::None do
|
|
4
4
|
|
5
5
|
describe 'instance_for' do
|
6
6
|
it 'caches' do
|
7
|
-
described_class.instance_for.
|
7
|
+
expect(described_class.instance_for).to eq described_class.instance_for
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
@@ -13,13 +13,13 @@ describe Phony::NationalSplitters::None do
|
|
13
13
|
|
14
14
|
describe 'split' do
|
15
15
|
it 'splits correctly into ndc and rest' do
|
16
|
-
splitter.split('123456789').
|
16
|
+
expect(splitter.split('123456789')).to eq [nil, false, '123456789']
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
describe 'length' do
|
21
21
|
it 'is always 0' do
|
22
|
-
splitter.length.
|
22
|
+
expect(splitter.length).to be_zero
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -4,34 +4,30 @@ describe Phony::NationalSplitters::Variable do
|
|
4
4
|
|
5
5
|
describe 'split' do
|
6
6
|
context 'normal' do
|
7
|
-
|
8
|
-
@splitter = Phony::NationalSplitters::Variable.new 4, ['1', '316', '67', '68', '669', '711']
|
9
|
-
end
|
7
|
+
let(:splitter) { Phony::NationalSplitters::Variable.new 4, ['1', '316', '67', '68', '669', '711'] }
|
10
8
|
it "handles Vienna" do
|
11
|
-
|
9
|
+
expect(splitter.split('198110')).to eq [nil, '1', '98110']
|
12
10
|
end
|
13
11
|
it "handles some mobile services" do
|
14
|
-
|
12
|
+
expect(splitter.split('66914093902')).to eq [nil, '669', '14093902']
|
15
13
|
end
|
16
14
|
it "handles Graz" do
|
17
|
-
|
15
|
+
expect(splitter.split('3161234567891')).to eq [nil, '316', '1234567891']
|
18
16
|
end
|
19
17
|
it "handles Rohrau" do
|
20
|
-
|
18
|
+
expect(splitter.split('2164123456789')).to eq [nil, '2164', '123456789']
|
21
19
|
end
|
22
20
|
it 'has an NDC length of 3' do
|
23
|
-
|
21
|
+
expect(splitter.length).to eq (1..3)
|
24
22
|
end
|
25
23
|
end
|
26
24
|
context 'special handling for using the variable size splitter for Swiss service numbers' do
|
27
|
-
|
28
|
-
@splitter = Phony::NationalSplitters::Variable.new 2, ['800']
|
29
|
-
end
|
25
|
+
let(:splitter) { Phony::NationalSplitters::Variable.new 2, ['800'] }
|
30
26
|
it "should handle swiss service numbers" do
|
31
|
-
|
27
|
+
expect(splitter.split('800223344')).to eq [nil, '800', '223344']
|
32
28
|
end
|
33
29
|
it 'has an NDC length of 3' do
|
34
|
-
|
30
|
+
expect(splitter.length).to eq (3..3)
|
35
31
|
end
|
36
32
|
end
|
37
33
|
end
|
@@ -8,22 +8,22 @@ describe Phony::Vanity do
|
|
8
8
|
|
9
9
|
describe '.replace' do
|
10
10
|
it 'replaces letters with digits' do
|
11
|
-
vanity.replace('1-800-HELLO').
|
11
|
+
expect(vanity.replace('1-800-HELLO')).to eq '1-800-43556'
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
describe '.vanity?' do
|
16
16
|
it 'returns true on a vanity number' do
|
17
|
-
vanity.vanity?('800HELLOES').
|
17
|
+
expect(vanity.vanity?('800HELLOES')).to eq true
|
18
18
|
end
|
19
19
|
it 'returns false on a non-vanity number' do
|
20
|
-
vanity.vanity?('8004355637').
|
20
|
+
expect(vanity.vanity?('8004355637')).to eq false
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
describe '.normalized' do
|
25
25
|
it 'normalizes the vanity number' do
|
26
|
-
vanity.normalized('1-800-HELLO').
|
26
|
+
expect(vanity.normalized('1-800-HELLO')).to eq '1800HELLO'
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
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.20.
|
4
|
+
version: 2.20.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Hanke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-04-18 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
|
@@ -115,26 +115,26 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: '0'
|
117
117
|
requirements: []
|
118
|
-
rubygems_version: 3.
|
118
|
+
rubygems_version: 3.3.26
|
119
119
|
signing_key:
|
120
120
|
specification_version: 4
|
121
121
|
summary: Fast international phone number (E164 standard) normalizing, splitting and
|
122
122
|
formatting.
|
123
123
|
test_files:
|
124
|
-
- spec/
|
125
|
-
- spec/
|
126
|
-
- spec/lib/phony/country_spec.rb
|
127
|
-
- spec/lib/phony/national_code_spec.rb
|
124
|
+
- spec/functional/config_spec.rb
|
125
|
+
- spec/functional/plausibility_spec.rb
|
128
126
|
- spec/lib/phony/countries_spec.rb
|
127
|
+
- spec/lib/phony/country_codes_spec.rb
|
128
|
+
- spec/lib/phony/country_spec.rb
|
129
129
|
- spec/lib/phony/dsl_spec.rb
|
130
|
-
- spec/lib/phony/
|
130
|
+
- spec/lib/phony/local_splitters/fixed_spec.rb
|
131
|
+
- spec/lib/phony/local_splitters/regex_spec.rb
|
132
|
+
- spec/lib/phony/national_code_spec.rb
|
133
|
+
- spec/lib/phony/national_splitters/default_spec.rb
|
134
|
+
- spec/lib/phony/national_splitters/fixed_spec.rb
|
131
135
|
- spec/lib/phony/national_splitters/none_spec.rb
|
132
136
|
- spec/lib/phony/national_splitters/regex_spec.rb
|
133
|
-
- spec/lib/phony/national_splitters/
|
134
|
-
- spec/lib/phony/
|
135
|
-
- spec/lib/phony/country_codes_spec.rb
|
136
|
-
- spec/lib/phony/local_splitters/regex_spec.rb
|
137
|
-
- spec/lib/phony/local_splitters/fixed_spec.rb
|
137
|
+
- spec/lib/phony/national_splitters/variable_spec.rb
|
138
|
+
- spec/lib/phony/trunk_code_spec.rb
|
138
139
|
- spec/lib/phony/vanity_spec.rb
|
139
|
-
- spec/
|
140
|
-
- spec/functional/plausibility_spec.rb
|
140
|
+
- spec/lib/phony_spec.rb
|