phony 2.21.2 → 2.22.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.rb +2 -1
- data/lib/phony/country_codes.rb +5 -4
- data/lib/phony/local_splitters/fixed.rb +4 -2
- data/lib/phony/local_splitters/regex.rb +4 -2
- data/lib/phony/national_splitters/fixed.rb +1 -1
- data/lib/phony/national_splitters/variable.rb +1 -0
- data/lib/phony/trunk_code.rb +3 -3
- 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: 148f0154720cf8360fed738f7d1c4cba00dc5f4d796a443dc4edf05483f77db4
|
4
|
+
data.tar.gz: 8bc31fd2a97ac906ece21616d81ce0e4420afe68c066c529834e3723a9653fb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50bc05837db5ce9ebb6d8a9239b220bb2b33a4dd76aaa6b9b53444103296c359d7ef8e24b2f3c4dc978eb19ee59c9f284ebe58c737fd0a9a8b97178142f0de6f
|
7
|
+
data.tar.gz: e73c940e446cebd165726c9122251f2c7e15b9ad342d76ff2413b7860a80457ff754097bb3bf381595b4fa1a882600255b719a957bf802c4ba7c5e3014c54442
|
data/lib/phony/country.rb
CHANGED
@@ -62,7 +62,7 @@ module Phony
|
|
62
62
|
@codes.each do |national_splitter|
|
63
63
|
new_trunk, ndc, *rest = national_splitter.split national_number
|
64
64
|
trunk ||= new_trunk
|
65
|
-
national_number
|
65
|
+
national_number = ndc if new_trunk
|
66
66
|
return [national_splitter.local_splitter, trunk, ndc, *rest] if rest && !rest.empty?
|
67
67
|
end
|
68
68
|
|
@@ -167,6 +167,7 @@ module Phony
|
|
167
167
|
# Note: Options such as CC
|
168
168
|
#
|
169
169
|
def normalize(national_number, options = {})
|
170
|
+
national_number = national_number.dup
|
170
171
|
clean! national_number
|
171
172
|
@codes.each_with_object national_number do |code, number|
|
172
173
|
result = code.normalize number, options
|
data/lib/phony/country_codes.rb
CHANGED
@@ -60,6 +60,7 @@ module Phony
|
|
60
60
|
# * Non-digits.
|
61
61
|
#
|
62
62
|
def normalize(number, options = {})
|
63
|
+
number = number.dup
|
63
64
|
country = if (cc = options[:cc])
|
64
65
|
self[cc]
|
65
66
|
else
|
@@ -158,11 +159,11 @@ module Phony
|
|
158
159
|
# Split off the country and the cc, and also return the national number part.
|
159
160
|
#
|
160
161
|
def partial_split(number)
|
161
|
-
cc = +''
|
162
162
|
1.upto(3) do |i|
|
163
|
-
cc
|
163
|
+
cc = number.slice(...i)
|
164
|
+
national_number = number.slice(i..)
|
164
165
|
country = countries[i][cc]
|
165
|
-
return [country, cc,
|
166
|
+
return [country, cc, national_number] if country
|
166
167
|
end
|
167
168
|
# This line is never reached as CCs are in prefix code.
|
168
169
|
end
|
@@ -173,7 +174,7 @@ module Phony
|
|
173
174
|
# Note: This won't be correct in some cases, but it is the best we can do.
|
174
175
|
#
|
175
176
|
def countrify(number, cc)
|
176
|
-
countrify!(number, cc) || number
|
177
|
+
countrify!(number.dup, cc) || number
|
177
178
|
end
|
178
179
|
|
179
180
|
def countrify!(number, cc)
|
@@ -49,9 +49,11 @@ module Phony
|
|
49
49
|
# * split '3643533' # => ['364', '35', '33'] # (Switzerland)
|
50
50
|
#
|
51
51
|
def split(number)
|
52
|
+
cursor = 0
|
52
53
|
@format.each_with_object([]) do |size, result|
|
53
|
-
result << number.slice
|
54
|
-
|
54
|
+
result << number.slice(cursor...cursor + size)
|
55
|
+
cursor += size
|
56
|
+
return result if cursor >= number.size
|
55
57
|
end
|
56
58
|
end
|
57
59
|
|
@@ -55,9 +55,11 @@ module Phony
|
|
55
55
|
private
|
56
56
|
|
57
57
|
def split_with(number, format)
|
58
|
+
cursor = 0
|
58
59
|
format.each_with_object([]) do |size, result|
|
59
|
-
result << number.slice
|
60
|
-
|
60
|
+
result << number.slice(cursor...cursor + size)
|
61
|
+
cursor += size
|
62
|
+
return result if cursor >= number.size
|
61
63
|
end << number
|
62
64
|
end
|
63
65
|
|
@@ -27,7 +27,7 @@ module Phony
|
|
27
27
|
def split(national_number)
|
28
28
|
return [@zero, national_number] unless @size
|
29
29
|
|
30
|
-
[@zero, national_number.slice
|
30
|
+
[@zero, national_number.slice(0...@size), national_number.slice(@size..)]
|
31
31
|
end
|
32
32
|
|
33
33
|
# A valid length.
|
data/lib/phony/trunk_code.rb
CHANGED
@@ -38,8 +38,9 @@ module Phony
|
|
38
38
|
# Normalize normalizes the given national number.
|
39
39
|
#
|
40
40
|
def normalize(national_number, options = {})
|
41
|
-
national_number
|
42
|
-
|
41
|
+
return national_number unless @normalize && options[:cc]
|
42
|
+
|
43
|
+
national_number.gsub @trunk_code_replacement, EMPTY_STRING
|
43
44
|
end
|
44
45
|
|
45
46
|
# Format the trunk code using the spaces given.
|
@@ -51,7 +52,6 @@ module Phony
|
|
51
52
|
else
|
52
53
|
@code
|
53
54
|
end
|
54
|
-
|
55
55
|
end
|
56
56
|
end
|
57
57
|
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.22.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: 2025-
|
11
|
+
date: 2025-03-01 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
|