phonelib 0.6.11 → 0.6.12
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/data/extended_data.dat +0 -0
- data/data/phone_data.dat +0 -0
- data/lib/phonelib/core.rb +3 -0
- data/lib/phonelib/data_importer.rb +20 -7
- data/lib/phonelib/data_importer_helper.rb +28 -1
- data/lib/phonelib/phone_analyzer.rb +6 -3
- data/lib/phonelib/phone_analyzer_helper.rb +15 -1
- data/lib/phonelib/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a160b71aed28582490691f2c087b27908f2df154
|
4
|
+
data.tar.gz: 0a33eb3d681531632e0663826a75d7825e284e67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 241b111cf80d110df3f4cf27b3bdfe348ff87f3154c8bedd2241439b17594c517323d0c4917891ea23b9c3e95e5a153a704c313d8f58184d565e4e0c3645ccb6
|
7
|
+
data.tar.gz: 787995a5acc1ff9cd308a7a359011659566e404c113f53815c4e23ca27c0d77930e47cd952d66181eeb8f491cb379aa612922ad8215037d5cf8557fe2861fd83
|
data/data/extended_data.dat
CHANGED
Binary file
|
data/data/phone_data.dat
CHANGED
Binary file
|
data/lib/phonelib/core.rb
CHANGED
@@ -50,7 +50,7 @@ module Phonelib
|
|
50
50
|
|
51
51
|
# running import method
|
52
52
|
def run_import
|
53
|
-
clone_repo
|
53
|
+
#clone_repo
|
54
54
|
import_main_data
|
55
55
|
import_short_data
|
56
56
|
import_alternate_formats
|
@@ -147,7 +147,9 @@ module Phonelib
|
|
147
147
|
result = { types: {}, formats: [] }
|
148
148
|
|
149
149
|
without_comments(children).each do |phone_type|
|
150
|
-
if phone_type.name == '
|
150
|
+
if phone_type.name == 'references'
|
151
|
+
next
|
152
|
+
elsif phone_type.name == 'availableFormats'
|
151
153
|
result[:formats] = parse_formats(phone_type.children)
|
152
154
|
else
|
153
155
|
result[:types][name2sym(phone_type.name)] =
|
@@ -161,11 +163,12 @@ module Phonelib
|
|
161
163
|
# method adds short number patterns to main data parsed from main xml
|
162
164
|
def merge_short_with_main_type(country_id, type, data)
|
163
165
|
@data[country_id][:types][type] ||= {}
|
166
|
+
@data[country_id][:types][type][Core::SHORT] ||= {}
|
164
167
|
data.each do |k, v|
|
165
|
-
if @data[country_id][:types][type][k]
|
166
|
-
@data[country_id][:types][type][k] += "|#{v}"
|
168
|
+
if @data[country_id][:types][type][Core::SHORT][k]
|
169
|
+
@data[country_id][:types][type][Core::SHORT][k] += "|#{v}"
|
167
170
|
else
|
168
|
-
@data[country_id][:types][type][k] = v
|
171
|
+
@data[country_id][:types][type][Core::SHORT][k] = v
|
169
172
|
end
|
170
173
|
end
|
171
174
|
end
|
@@ -174,13 +177,23 @@ module Phonelib
|
|
174
177
|
def fill_possible_to_types_if_nil(result)
|
175
178
|
result[:types].each do |type, data|
|
176
179
|
if data[Core::VALID_PATTERN] && !data[Core::POSSIBLE_PATTERN]
|
177
|
-
result[:types][type][Core::POSSIBLE_PATTERN] =
|
178
|
-
|
180
|
+
result[:types][type][Core::POSSIBLE_PATTERN] = case type
|
181
|
+
when Core::GENERAL
|
182
|
+
national_possible result[:types]
|
183
|
+
else
|
184
|
+
data[Core::VALID_PATTERN]
|
185
|
+
end
|
179
186
|
end
|
180
187
|
end
|
181
188
|
result
|
182
189
|
end
|
183
190
|
|
191
|
+
# take all possible patters from all types
|
192
|
+
def national_possible(types)
|
193
|
+
types.map { |k, v| v[:possible_number_pattern] }.
|
194
|
+
compact.map { |e| e.split('|') }.flatten.uniq.join('|')
|
195
|
+
end
|
196
|
+
|
184
197
|
# method parses xml for formats data
|
185
198
|
def parse_formats(formats_children)
|
186
199
|
without_comments(formats_children).map do |format|
|
@@ -71,12 +71,39 @@ module Phonelib
|
|
71
71
|
end
|
72
72
|
when :element
|
73
73
|
data.elements.each do |child|
|
74
|
-
|
74
|
+
if child.name == 'possibleLengths'
|
75
|
+
hash[Core::POSSIBLE_PATTERN] =
|
76
|
+
possible_length_regex(hash_from_xml(child, :attributes))
|
77
|
+
else
|
78
|
+
hash[name2sym(child.name)] = str_clean(child.children.first)
|
79
|
+
end
|
75
80
|
end
|
76
81
|
end
|
77
82
|
hash
|
78
83
|
end
|
79
84
|
|
85
|
+
def possible_length_regex(attributes)
|
86
|
+
return '' unless attributes[:national]
|
87
|
+
attributes[:national].split(',').map do |m|
|
88
|
+
if m.include? '-'
|
89
|
+
"\\d{#{m.gsub(/[\[\]]/, '').gsub('-', ',')}}"
|
90
|
+
else
|
91
|
+
"\\d{#{m}}"
|
92
|
+
end
|
93
|
+
end.join('|')
|
94
|
+
=begin
|
95
|
+
attributes.map do |k, v|
|
96
|
+
v.split(',').map do |m|
|
97
|
+
if m.include? '-'
|
98
|
+
"\\d{#{m.gsub(/[\[\]]/, '').gsub('-', ',')}}"
|
99
|
+
else
|
100
|
+
"\\d{#{m}}"
|
101
|
+
end
|
102
|
+
end.join('|')
|
103
|
+
end.join('|')
|
104
|
+
=end
|
105
|
+
end
|
106
|
+
|
80
107
|
# method parses raw data file
|
81
108
|
def parse_raw_file(file)
|
82
109
|
data = {}
|
@@ -187,10 +187,13 @@ module Phonelib
|
|
187
187
|
type = Core::FIXED_LINE if type == Core::FIXED_OR_MOBILE
|
188
188
|
patterns = all_patterns[type]
|
189
189
|
|
190
|
-
if patterns
|
191
|
-
[
|
190
|
+
if patterns
|
191
|
+
[
|
192
|
+
type_regex(patterns, Core::POSSIBLE_PATTERN),
|
193
|
+
type_regex(patterns, Core::VALID_PATTERN)
|
194
|
+
]
|
192
195
|
else
|
193
|
-
[
|
196
|
+
[nil, nil]
|
194
197
|
end
|
195
198
|
end
|
196
199
|
end
|
@@ -105,11 +105,25 @@ module Phonelib
|
|
105
105
|
regex << "(#{data[Core::INTERNATIONAL_PREFIX]})?"
|
106
106
|
regex << "(#{data[Core::COUNTRY_CODE]})#{country_optional ? '?' : ''}"
|
107
107
|
regex << "(#{data[Core::NATIONAL_PREFIX_FOR_PARSING] || data[Core::NATIONAL_PREFIX]})?"
|
108
|
-
regex << "(#{data[Core::TYPES][Core::GENERAL]
|
108
|
+
regex << "(#{type_regex(data[Core::TYPES][Core::GENERAL], type)})"
|
109
109
|
|
110
110
|
cr("^#{regex.join}$")
|
111
111
|
end
|
112
112
|
|
113
|
+
# Returns regex for type with special types if needed
|
114
|
+
#
|
115
|
+
# ==== Attributes
|
116
|
+
#
|
117
|
+
# * +data+ - country types data for single type
|
118
|
+
# * +type+ - possible or valid regex type needed
|
119
|
+
def type_regex(data, type)
|
120
|
+
regex = [data[type]]
|
121
|
+
if Phonelib.parse_special && data[Core::SHORT] && data[Core::SHORT][type]
|
122
|
+
regex << data[Core::SHORT][type]
|
123
|
+
end
|
124
|
+
regex.join('|')
|
125
|
+
end
|
126
|
+
|
113
127
|
# Check if phone match country data
|
114
128
|
#
|
115
129
|
# ==== Attributes
|
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.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vadim Senderovich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-06-03 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
|
version: '0'
|
170
170
|
requirements: []
|
171
171
|
rubyforge_project:
|
172
|
-
rubygems_version: 2.
|
172
|
+
rubygems_version: 2.6.11
|
173
173
|
signing_key:
|
174
174
|
specification_version: 4
|
175
175
|
summary: Gem validates phone numbers with Google libphonenumber database
|