phonelib 0.6.56 → 0.7.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/README.md +7 -2
- data/data/extended_data.dat +0 -0
- data/data/phone_data.dat +0 -0
- data/lib/phonelib/data_importer.rb +50 -0
- data/lib/phonelib/phone_analyzer.rb +24 -3
- data/lib/phonelib/phone_analyzer_helper.rb +13 -1
- data/lib/phonelib/version.rb +1 -1
- 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: d9a96a615d554195979c6dc886188eb4f8638e89f616fb5ce5aa6cb74ee91ca0
|
|
4
|
+
data.tar.gz: e8b51d76743373fd9e2913eb5eddcea65e35e57673f29e47a361398dab662a16
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7710f2ab513e1bb53bb6bec2fe78de93fa742c18c85f2393f05ebf862cd245c7b3b01a4055403af287c4e225a58c26fd03507f0f08bf9e4d1468ad1279623ecd
|
|
7
|
+
data.tar.gz: e44959fbc033b27ac6b2974941c2ce010ba788bf371a4048a45c7d3dba78bb982b08c9201019b4bd2f958b139e46f7f29dcf0c0ae6c406a94d21490129df68de
|
data/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.jetbrains.com/ruby/)
|
|
4
4
|
[](http://badge.fury.io/rb/phonelib)
|
|
5
|
-
[](https://circleci.com/gh/daddyz/phonelib/tree/master)
|
|
6
6
|
[](https://codeclimate.com/github/daddyz/phonelib/coverage)
|
|
7
7
|
[](https://codeclimate.com/github/daddyz/phonelib)
|
|
8
8
|
[](http://inch-ci.org/github/daddyz/phonelib)
|
|
@@ -11,6 +11,11 @@ Phonelib is a gem allowing you to validate phone number. All validations are bas
|
|
|
11
11
|
Currently it can make basic validations and formatting to e164 international number format and national number format with prefix.
|
|
12
12
|
But it still doesn't include all Google's library functionality.
|
|
13
13
|
|
|
14
|
+
## Incorrect parsing or validation
|
|
15
|
+
|
|
16
|
+
In case your phone number is incorrectly parsed, you can check original libphonenumber for result [here](https://rawgit.com/googlei18n/libphonenumber/master/javascript/i18n/phonenumbers/demo-compiled.html) and in case of same parse result [open an issue for them](https://issuetracker.google.com/issues/new?component=192347&template=829703). This gem's data is based on it.
|
|
17
|
+
If you can't wait for libphonenumber to resolve the issue, try to use ```Phonelib.add_additional_regex``` and ```Phonelib.additional_regexes``` methods.
|
|
18
|
+
|
|
14
19
|
## Information
|
|
15
20
|
|
|
16
21
|
### Change Log
|
|
@@ -252,7 +257,7 @@ phone.full_e164 # returns e164 phone representation with extension
|
|
|
252
257
|
phone.full_international # returns formatted international number with extension
|
|
253
258
|
```
|
|
254
259
|
|
|
255
|
-
You can pass <tt>false</tt> to <tt>national</tt> and <tt>international</tt> methods in order to get unformatted
|
|
260
|
+
You can pass <tt>false</tt> to <tt>national</tt> and <tt>international</tt> methods in order to get unformatted representations
|
|
256
261
|
|
|
257
262
|
``` ruby
|
|
258
263
|
phone.international(false) # returns unformatted international phone
|
data/data/extended_data.dat
CHANGED
|
Binary file
|
data/data/phone_data.dat
CHANGED
|
Binary file
|
|
@@ -19,6 +19,47 @@ module Phonelib
|
|
|
19
19
|
|
|
20
20
|
# countries that can have double country prefix in number
|
|
21
21
|
DOUBLE_COUNTRY_CODES_COUNTRIES = %w(IN DE BR IT NO PL CU VN)
|
|
22
|
+
FORMAT_SHARING = {
|
|
23
|
+
'CA' => 'US',
|
|
24
|
+
'CC' => 'AU',
|
|
25
|
+
'CX' => 'AU',
|
|
26
|
+
'DM' => 'US',
|
|
27
|
+
'DO' => 'US',
|
|
28
|
+
'EH' => 'MA',
|
|
29
|
+
'GD' => 'US',
|
|
30
|
+
'GG' => 'GB',
|
|
31
|
+
'GU' => 'US',
|
|
32
|
+
'IM' => 'GB',
|
|
33
|
+
'JE' => 'GB',
|
|
34
|
+
'JM' => 'US',
|
|
35
|
+
'KN' => 'US',
|
|
36
|
+
'KY' => 'US',
|
|
37
|
+
'KZ' => 'RU',
|
|
38
|
+
'LC' => 'US',
|
|
39
|
+
'MF' => 'GP',
|
|
40
|
+
'MP' => 'US',
|
|
41
|
+
'MS' => 'US',
|
|
42
|
+
'PR' => 'US',
|
|
43
|
+
'SJ' => 'NO',
|
|
44
|
+
'SX' => 'US',
|
|
45
|
+
'TA' => 'SH',
|
|
46
|
+
'TC' => 'US',
|
|
47
|
+
'TT' => 'US',
|
|
48
|
+
'VA' => 'IT',
|
|
49
|
+
'VC' => 'US',
|
|
50
|
+
'VG' => 'US',
|
|
51
|
+
'VI' => 'US',
|
|
52
|
+
'YT' => 'RE',
|
|
53
|
+
'AG' => 'US',
|
|
54
|
+
'AI' => 'US',
|
|
55
|
+
'AS' => 'US',
|
|
56
|
+
'AX' => 'FI',
|
|
57
|
+
'BB' => 'US',
|
|
58
|
+
'BL' => 'GP',
|
|
59
|
+
'BM' => 'US',
|
|
60
|
+
'BQ' => 'CW',
|
|
61
|
+
'BS' => 'US',
|
|
62
|
+
}
|
|
22
63
|
|
|
23
64
|
# main data file in repo
|
|
24
65
|
MAIN_FILE = 'resources/PhoneNumberMetadata.xml'
|
|
@@ -55,6 +96,7 @@ module Phonelib
|
|
|
55
96
|
import_main_data
|
|
56
97
|
import_short_data
|
|
57
98
|
import_alternate_formats
|
|
99
|
+
process_format_links
|
|
58
100
|
import_geocoding_data
|
|
59
101
|
import_timezone_data
|
|
60
102
|
import_carrier_data
|
|
@@ -115,6 +157,14 @@ module Phonelib
|
|
|
115
157
|
end
|
|
116
158
|
end
|
|
117
159
|
|
|
160
|
+
# some countries missing formats, and are linking them to another countries
|
|
161
|
+
def process_format_links
|
|
162
|
+
FORMAT_SHARING.each do |destination, source|
|
|
163
|
+
@data[destination][:formats] ||= []
|
|
164
|
+
@data[destination][:formats] = @data[destination][:formats] + @data[source][:formats]
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
118
168
|
# method parses geocoding data dir
|
|
119
169
|
def import_geocoding_data
|
|
120
170
|
puts 'IMPORTING GEOCODING DATA'
|
|
@@ -16,8 +16,31 @@ module Phonelib
|
|
|
16
16
|
# * +passed_country+ - Country provided for parsing. Must be ISO code of
|
|
17
17
|
# country (2 letters) like 'US', 'us' or :us for United States
|
|
18
18
|
def analyze(phone, passed_country)
|
|
19
|
-
|
|
19
|
+
countries = country_or_default_country passed_country
|
|
20
20
|
|
|
21
|
+
return analyze_single_country(phone, countries.first, passed_country) if countries.size == 1
|
|
22
|
+
|
|
23
|
+
results = {}
|
|
24
|
+
countries.map do |country|
|
|
25
|
+
results.merge! analyze_single_country(phone, country, passed_country)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
pick_results(results)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
# pick best result when several countries specified
|
|
34
|
+
def pick_results(results)
|
|
35
|
+
[:valid, :possible].each do |key|
|
|
36
|
+
final = results.select { |_k, v| v[key].any? }
|
|
37
|
+
return decorate_analyze_result(final) if final.size > 0
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
decorate_analyze_result(results)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def analyze_single_country(phone, country, passed_country)
|
|
21
44
|
result = parse_country(phone, country)
|
|
22
45
|
d_result = case
|
|
23
46
|
when result && result.values.find { |e| e[:valid].any? }
|
|
@@ -32,8 +55,6 @@ module Phonelib
|
|
|
32
55
|
better_result(result, d_result)
|
|
33
56
|
end
|
|
34
57
|
|
|
35
|
-
private
|
|
36
|
-
|
|
37
58
|
# method checks which result is better to return
|
|
38
59
|
def better_result(base_result, result = nil)
|
|
39
60
|
base_result ||= {}
|
|
@@ -3,6 +3,14 @@ module Phonelib
|
|
|
3
3
|
module PhoneAnalyzerHelper
|
|
4
4
|
private
|
|
5
5
|
|
|
6
|
+
def decorate_analyze_result(result)
|
|
7
|
+
if result.size == 1
|
|
8
|
+
result
|
|
9
|
+
else
|
|
10
|
+
Hash[result.take(1)]
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
6
14
|
def original_starts_with_plus?
|
|
7
15
|
original_s[0] == Core::PLUS_SIGN
|
|
8
16
|
end
|
|
@@ -90,7 +98,11 @@ module Phonelib
|
|
|
90
98
|
# * +country+ - country passed for parsing
|
|
91
99
|
def country_or_default_country(country)
|
|
92
100
|
country ||= (original_starts_with_plus? ? nil : Phonelib.default_country)
|
|
93
|
-
|
|
101
|
+
if country.is_a?(Array)
|
|
102
|
+
country.compact.map { |e| e.to_s.upcase }
|
|
103
|
+
else
|
|
104
|
+
[country && country.to_s.upcase]
|
|
105
|
+
end
|
|
94
106
|
end
|
|
95
107
|
|
|
96
108
|
# constructs full regex for phone validation for provided phone data
|
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.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Vadim Senderovich
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2022-
|
|
11
|
+
date: 2022-06-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|