phony 2.19.13 → 2.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.textile +4 -0
- data/lib/phony/countries/italy.rb +18 -16
- data/lib/phony/countries.rb +1 -0
- data/lib/phony/country_codes.rb +13 -0
- data/spec/functional/plausibility_spec.rb +22 -2
- data/spec/lib/phony/countries_spec.rb +1 -1
- data/spec/lib/phony/country_codes_spec.rb +21 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53e35e946aea7db6e2c7901a5df43de446fc04289fa976f4d2d655a09f4bdbae
|
4
|
+
data.tar.gz: f7f0cb0e4ee68d31a754d2c57fcde82116907fced053416c630eafcf71e8cd12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e43b987e4313294e70a389da3441e364c8c0cd4930344c2beaadaef58cc60afdf3fc8f265e75923968f8dba565988237067375d41f9546f1dae1c9d258c6aa3
|
7
|
+
data.tar.gz: b3d7ba6dd615c1d36be9b284da5a578c1f8d11937230bf73185f172250c74d17ffb5a00fe2002f787731c2970587c3e19c1be012469227f28763563389c2da95
|
data/README.textile
CHANGED
@@ -106,6 +106,10 @@ h2. List of Handled Countries
|
|
106
106
|
|
107
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
|
+
h2. Proud Sponsors
|
110
|
+
|
111
|
+
* Renuo AG (July 22 –): "Github":https://github.com/renuo, "Homepage":https://www.renuo.ch
|
112
|
+
|
109
113
|
h2. License
|
110
114
|
|
111
115
|
MIT.
|
@@ -3,14 +3,14 @@
|
|
3
3
|
# Italian phone numbers.
|
4
4
|
#
|
5
5
|
# http://en.wikipedia.org/wiki/Telephone_numbers_in_Italy
|
6
|
-
#
|
6
|
+
# https://www.itu.int/dms_pub/itu-t/oth/02/02/T020200006B0001PDFE.pdf
|
7
7
|
|
8
|
-
|
8
|
+
ndcs_1digit = [
|
9
9
|
'02', # Milan
|
10
10
|
'06', # Rome (including State of Vatican City) and Aprilia
|
11
11
|
]
|
12
12
|
|
13
|
-
|
13
|
+
ndcs_2digit = [
|
14
14
|
'010', # Genoa
|
15
15
|
'011', # Turin
|
16
16
|
'015', # Biella
|
@@ -42,7 +42,7 @@ ndcs_3digit = [
|
|
42
42
|
'099', # Taranto
|
43
43
|
]
|
44
44
|
|
45
|
-
|
45
|
+
ndcs_3digit = [
|
46
46
|
'0121', # Pinerolo
|
47
47
|
'0122', # Sestrieres, Bardonecchia and other Susa Valley mountain resorts
|
48
48
|
'0123', # Lanzo Torinese
|
@@ -269,26 +269,28 @@ service = [ # Not exhaustive.
|
|
269
269
|
]
|
270
270
|
|
271
271
|
Phony.define do
|
272
|
+
# Note: The 0 does not count towards NDC number length.
|
272
273
|
country '39', trunk('', normalize: false) |
|
273
274
|
one_of(*service) >> split(3,3) |
|
274
275
|
one_of(*mobile) >> split(3,4,-1..1) |
|
275
|
-
one_of(*
|
276
|
+
one_of(*ndcs_1digit) >> matched_split(
|
276
277
|
/\A\d{5}\z/ => [5],
|
277
278
|
/\A\d{6}\z/ => [4,2],
|
278
279
|
/\A\d{7}\z/ => [4,3],
|
279
280
|
/\A\d{8}\z/ => [4,4],
|
280
281
|
) |
|
281
|
-
one_of(*
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
282
|
+
one_of(*ndcs_2digit) >> matched_split(
|
283
|
+
/\A\d{4}\z/ => [4],
|
284
|
+
/\A\d{5}\z/ => [5],
|
285
|
+
/\A\d{6}\z/ => [6],
|
286
|
+
/\A\d{7}\z/ => [7],
|
287
|
+
/\A\d{8}\z/ => [8]
|
286
288
|
) |
|
287
|
-
one_of(*
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
289
|
+
one_of(*ndcs_3digit) >> matched_split(
|
290
|
+
/\A\d{4}\z/ => [4],
|
291
|
+
/\A1\d{5}\z/ => [6],
|
292
|
+
/\A1\d{6}\z/ => [7],
|
293
|
+
/\A[^1]\d{4}\z/ => [5],
|
294
|
+
/\A[^1]\d{5}\z/ => [3,3]
|
293
295
|
)
|
294
296
|
end
|
data/lib/phony/countries.rb
CHANGED
@@ -232,6 +232,7 @@ Phony.define do
|
|
232
232
|
# http://www.itu.int/oth/T020200002C/en
|
233
233
|
country '57',
|
234
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) |
|
235
236
|
fixed(1) >> split(3,4)
|
236
237
|
|
237
238
|
# Venezuela (Bolivarian Republic of)
|
data/lib/phony/country_codes.rb
CHANGED
@@ -100,6 +100,17 @@ module Phony
|
|
100
100
|
return false unless (4..16) === normalized.size # unless hints[:check_length] == false
|
101
101
|
|
102
102
|
country, cc, rest = partial_split normalized
|
103
|
+
|
104
|
+
# Was a country calling code given?
|
105
|
+
#
|
106
|
+
if ccc = hints[:ccc]
|
107
|
+
cc, ndc, *local = split ccc
|
108
|
+
|
109
|
+
raise ArgumentError.new("The provided ccc option is too long and includes more than a cc ('#{cc}') and ndc ('#{ndc}'). It also includes '#{local.join}'.") unless local.size == 1 && local[0].empty?
|
110
|
+
|
111
|
+
hints[:cc] = cc
|
112
|
+
hints[:ndc] = ndc
|
113
|
+
end
|
103
114
|
|
104
115
|
# Country code plausible?
|
105
116
|
#
|
@@ -109,6 +120,8 @@ module Phony
|
|
109
120
|
# Country specific tests.
|
110
121
|
#
|
111
122
|
country.plausible? rest, hints
|
123
|
+
rescue ArgumentError
|
124
|
+
raise
|
112
125
|
rescue StandardError
|
113
126
|
return false
|
114
127
|
end
|
@@ -179,6 +179,14 @@ describe 'plausibility' do
|
|
179
179
|
Phony.plausible?('+359 998 123456').should be_truthy
|
180
180
|
Phony.plausible?('+359 999 123456').should be_truthy
|
181
181
|
end
|
182
|
+
it_is_correct_for 'Colombia', :samples => ['+57 601 411 1899',
|
183
|
+
'+57 602 111 2222',
|
184
|
+
'+57 603 111 2222',
|
185
|
+
'+57 604 111 2222',
|
186
|
+
'+57 605 111 2222',
|
187
|
+
'+57 606 111 2222',
|
188
|
+
'+57 607 111 2222',
|
189
|
+
'+57 608 111 2222']
|
182
190
|
it_is_correct_for 'Congo', :samples => '+242 1234 56789'
|
183
191
|
it_is_correct_for 'Cook Islands', :samples => '+682 71928'
|
184
192
|
it_is_correct_for 'Costa Rica', :samples => '+506 2 234 5678'
|
@@ -280,8 +288,6 @@ describe 'plausibility' do
|
|
280
288
|
it_is_correct_for 'Guinea-Bissau', :samples => '+245 44 728 6998'
|
281
289
|
it_is_correct_for 'Guyana', :samples => '+592 263 1234'
|
282
290
|
it_is_correct_for 'Honduras (Republic of)', :samples => '+504 12 961 637'
|
283
|
-
it_is_correct_for 'Italy', :samples => ['+39 0574 1234',
|
284
|
-
'+39 06 49911']
|
285
291
|
it_is_correct_for 'Iraq', :samples => ['+964 1 123 4567',
|
286
292
|
'+964 21 113 456',
|
287
293
|
'+964 71 1234 5678']
|
@@ -602,6 +608,20 @@ describe 'plausibility' do
|
|
602
608
|
Phony.plausible?('+62 22 0000 0000').should be_truthy
|
603
609
|
Phony.plausible?('+62 22 000 000 000').should be_truthy
|
604
610
|
end
|
611
|
+
|
612
|
+
it 'is correct for Italy' do
|
613
|
+
Phony.plausible?('+39 0574 123').should be_falsy
|
614
|
+
Phony.plausible?('+39 0574 1234').should be_truthy
|
615
|
+
Phony.plausible?('+39 0574 12345').should be_falsy
|
616
|
+
|
617
|
+
Phony.plausible?('+39 085 541').should be_falsy
|
618
|
+
Phony.plausible?('+39 085 5410').should be_truthy
|
619
|
+
Phony.plausible?('+39 085 54105').should be_truthy
|
620
|
+
|
621
|
+
Phony.plausible?('+39 06 4991').should be_falsy
|
622
|
+
Phony.plausible?('+39 06 49911').should be_truthy
|
623
|
+
Phony.plausible?('+39 06 499112').should be_truthy
|
624
|
+
end
|
605
625
|
|
606
626
|
it 'is correct for Russia' do
|
607
627
|
Phony.plausible?('+7 3522 000 000').should be_truthy
|
@@ -240,7 +240,7 @@ describe 'country descriptions' do
|
|
240
240
|
end
|
241
241
|
end
|
242
242
|
describe 'Colombia' do
|
243
|
-
it_splits '5711234567', ['57', '1', '123', '4567']
|
243
|
+
it_splits '5711234567', ['57', '1', '123', '4567'] # Outdated.
|
244
244
|
it_splits '573101234567', ['57', '310', '123', '4567'] # mobile
|
245
245
|
end
|
246
246
|
describe 'Croatia' do
|
@@ -4,6 +4,27 @@ describe Phony::CountryCodes do
|
|
4
4
|
|
5
5
|
let(:countries) { Phony::CountryCodes.instance }
|
6
6
|
|
7
|
+
describe '#plausible?' do
|
8
|
+
it 'raises an error on a too long ccc' do
|
9
|
+
expect do
|
10
|
+
countries.plausible?('+1 868 7620266', ccc: '1868123')
|
11
|
+
end.to raise_error(ArgumentError, %Q{The provided ccc option is too long and includes more than a cc ('1') and ndc ('868'). It also includes '123'.})
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'ccc handling' do
|
16
|
+
it 'splits a ccc correctly' do
|
17
|
+
cc, ndc, *local = countries.split('1868')
|
18
|
+
cc.should eq('1')
|
19
|
+
ndc.should eq('868')
|
20
|
+
end
|
21
|
+
it 'splits a ccc correctly' do
|
22
|
+
cc, ndc, *local = countries.split('1868')
|
23
|
+
cc.should eq('1')
|
24
|
+
ndc.should eq('868')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
7
28
|
describe '#[]' do
|
8
29
|
it 'returns a country' do
|
9
30
|
countries['41'].class.should eql Phony::Country
|
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.20.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Hanke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-07-29 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
|