phonelib 0.6.48 → 0.6.52
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -0
- data/data/extended_data.dat +0 -0
- data/data/phone_data.dat +0 -0
- data/lib/phonelib/core.rb +51 -0
- data/lib/phonelib/phone.rb +3 -0
- data/lib/phonelib/phone_extended_data.rb +1 -1
- data/lib/phonelib/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dddd33a5cee524ab9b4838ef9cf4857271f8f2d425791b165469f07bd3ebf8cb
|
4
|
+
data.tar.gz: 0c62ef36c5cae469aea4a6759262c15cd494f5cc03ed8fbb0450c57a0d82f9d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5dacc59d0697e724eb461b4306a7d5fc3a804a9c557eb83c56947ec3656559213f23337656c62eea1bb1aeee96f0bc41ca9d0093b438e12aecbea59b671ffca3
|
7
|
+
data.tar.gz: 0f3c6f0eef8dbc9f660c981e254e7ecb6663a605b61f185095b41dc33a42a7f5093397c79fec2106a3d06d78ce99960b674ac457312b7b410c47fced46b579b2
|
data/README.md
CHANGED
@@ -92,6 +92,21 @@ In case you need to overwrite some Google's libphonenumber library data, you nee
|
|
92
92
|
Phonelib.override_phone_data = '/path/to/override_phone_data.dat'
|
93
93
|
```
|
94
94
|
|
95
|
+
In case you want to add some custom or still not updated regex patterns for certain type you can use additional regexes feature in a following way:
|
96
|
+
|
97
|
+
``` ruby
|
98
|
+
Phonelib.add_additional_regex :us, Phonelib::Core::MOBILE, '[5]{10}' # this will add number 1-555-555-5555 to be valid
|
99
|
+
Phonelib.add_additional_regex :gb, Phonelib::Core::MOBILE, '[1]{5}' # this will add number 44-11-111 to be valid
|
100
|
+
# you can also specify all regexes using this method
|
101
|
+
Phonelib.additional_regexes = [[:us, :mobile, "[5]{10}"], [:gb, :mobile, "[1]{5}"]]
|
102
|
+
# or just use dump method to keep them altogether
|
103
|
+
Phonelib.dump_additional_regexes # => [["US", :mobile, "[5]{10}"], ["GB", :mobile, "[1]{5}"]
|
104
|
+
```
|
105
|
+
|
106
|
+
(!) For a list of available types refer to this readme.
|
107
|
+
|
108
|
+
(!) Please note that regex should be added as string
|
109
|
+
|
95
110
|
In case phone number that was passed for parsing has "+" sign in the beginning, library will try to detect a country regarding the provided one.
|
96
111
|
|
97
112
|
### ActiveRecord Integration
|
data/data/extended_data.dat
CHANGED
Binary file
|
data/data/phone_data.dat
CHANGED
Binary file
|
data/lib/phonelib/core.rb
CHANGED
@@ -149,6 +149,42 @@ module Phonelib
|
|
149
149
|
@@override_phone_data
|
150
150
|
end
|
151
151
|
|
152
|
+
@@additional_regexes = {}
|
153
|
+
# setter for data file to use
|
154
|
+
def additional_regexes=(data)
|
155
|
+
return unless data.is_a?(Array)
|
156
|
+
@@additional_regexes = {}
|
157
|
+
data.each do |row|
|
158
|
+
next if row.size != 3
|
159
|
+
add_additional_regex(*row)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def add_additional_regex(country, type, national_regex)
|
164
|
+
return unless Phonelib::Core::TYPES_DESC.keys.include?(type.to_sym)
|
165
|
+
return unless national_regex.is_a?(String)
|
166
|
+
@@phone_data = nil
|
167
|
+
@@additional_regexes[country.to_s.upcase] ||= {}
|
168
|
+
@@additional_regexes[country.to_s.upcase][type] ||= []
|
169
|
+
@@additional_regexes[country.to_s.upcase][type] << national_regex
|
170
|
+
end
|
171
|
+
|
172
|
+
def dump_additional_regexes
|
173
|
+
rows = []
|
174
|
+
@@additional_regexes.each do |country, types|
|
175
|
+
types.each do |type, regexes|
|
176
|
+
regexes.each do |regex|
|
177
|
+
rows << [country, type, regex]
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
rows
|
182
|
+
end
|
183
|
+
|
184
|
+
def additional_regexes
|
185
|
+
@@additional_regexes
|
186
|
+
end
|
187
|
+
|
152
188
|
@@vanity_conversion = false
|
153
189
|
# setter for vanity phone numbers chars replacement
|
154
190
|
def vanity_conversion=(value)
|
@@ -393,6 +429,21 @@ module Phonelib
|
|
393
429
|
override_data_file = Marshal.load(File.binread(override_phone_data))
|
394
430
|
default_data.merge!(override_data_file)
|
395
431
|
end
|
432
|
+
additional_regexes.each do |country, types|
|
433
|
+
types.each do |type, regex|
|
434
|
+
default_data[country][Core::TYPES][type] ||= {}
|
435
|
+
[Core::VALID_PATTERN, Core::POSSIBLE_PATTERN].each do |key|
|
436
|
+
if default_data[country][Core::TYPES][type][key]
|
437
|
+
default_data[country][Core::TYPES][type][key] << "|#{regex.join('|')}"
|
438
|
+
else
|
439
|
+
default_data[country][Core::TYPES][type][key] = regex.join('|')
|
440
|
+
end
|
441
|
+
if type != Core::GENERAL
|
442
|
+
default_data[country][Core::TYPES][Core::GENERAL][key] << "|#{regex.join('|')}"
|
443
|
+
end
|
444
|
+
end
|
445
|
+
end
|
446
|
+
end
|
396
447
|
default_data
|
397
448
|
end
|
398
449
|
|
data/lib/phonelib/phone.rb
CHANGED
@@ -7,6 +7,9 @@ module Phonelib
|
|
7
7
|
# @!attribute [r] extension
|
8
8
|
# @return [String] phone extension passed for parsing after a number
|
9
9
|
attr_reader :extension
|
10
|
+
# @!attribute [r] national_number
|
11
|
+
# @return [String] phone national number
|
12
|
+
attr_reader :national_number
|
10
13
|
|
11
14
|
# including module that has all phone analyzing methods
|
12
15
|
include Phonelib::PhoneAnalyzer
|
data/lib/phonelib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phonelib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.52
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vadim Senderovich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -169,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
169
|
- !ruby/object:Gem::Version
|
170
170
|
version: '0'
|
171
171
|
requirements: []
|
172
|
-
rubygems_version: 3.0.
|
172
|
+
rubygems_version: 3.0.8
|
173
173
|
signing_key:
|
174
174
|
specification_version: 4
|
175
175
|
summary: Gem validates phone numbers with Google libphonenumber database
|