phony 2.19.15 → 2.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/phony/country_codes.rb +13 -0
- 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/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
|
@@ -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-07-
|
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
|