phony 2.19.15 → 2.20.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45ec2d2d9ab9772ae3f05cd031cd6d4214f1a541838ac8539e5a8d60039d5119
4
- data.tar.gz: 4998f527b3b6e2414ef7411c9736a39eaf4b9639faaca8d604a9802b1cf24d5b
3
+ metadata.gz: f2e0337c11693c028c028c978936d9753067bab16cceb1deba77f39e535fbb50
4
+ data.tar.gz: 45468532f0d66381ce8b52f8c500881ee6a34f134450f6ffac5b57193c1d4323
5
5
  SHA512:
6
- metadata.gz: 8fc13c0c16a9dd41bc947308ca2e0c36d59f4efce442c9d21a105aeb919ce323e8190ee0e302cd184e7145b26d6f3b3c9c42009ed6905240c7884fba98b98918
7
- data.tar.gz: 5cdc031002c1e727a852b67897d93e3c93c3aef931f1f9a563f62d0b37af9eb137a8e81b37648b57d05f1466e8bebcf0b175cba71215b4c97d7dc80fa78a5bdc
6
+ metadata.gz: 1c2ad0d4272a0eaf808bc95f8ace53b1d3c5f7fe2718bd555547b5611915eee4a5f34ea968ef7ebe8fb7b4b8cb86b9040b8af48a8181a7d287a9a39d9906f312
7
+ data.tar.gz: 0a2e811f7f43f4e357fbe384381565a884073d98e6f1376664df1f457cf210dc759bf50c140749e7447cb034cc40e9d2916a77d3c7555df7f922fa5f522652f0
@@ -489,13 +489,14 @@ Phony.define do
489
489
  # http://www.wtng.info/wtng-260-zm.html
490
490
  # https://github.com/googlei18n/libphonenumber/
491
491
  # https://en.wikipedia.org/wiki/Telephone_numbers_in_Zambia
492
+
492
493
  country '260',
493
494
  trunk('0') |
494
- match(/^(76|77|95|96|97)/) >> split(3, 4) | # Mobile
495
+ match(/^(75|76|77|94|95|96|97)/) >> split(3, 4) | # Mobile
495
496
  match(/^(800)/) >> split(3,3) | # Toll free
496
497
  match(/^(21[1-8])/) >> split(6) # Fixed
497
498
 
498
- # Madagascar
499
+ # Madagascar
499
500
  # https://en.wikipedia.org/wiki/Telephone_numbers_in_Madagascar
500
501
  # http://www.itu.int/oth/T020200007F/en
501
502
  country '261',
@@ -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.19.15
4
+ version: 2.20.1
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-27 00:00:00.000000000 Z
11
+ date: 2022-10-03 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