phonelib 0.6.26 → 0.6.27
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/data/extended_data.dat +0 -0
- data/data/phone_data.dat +0 -0
- data/lib/phonelib/core.rb +2 -0
- data/lib/phonelib/data_importer.rb +17 -0
- data/lib/phonelib/data_importer_helper.rb +1 -0
- data/lib/phonelib/phone_extended_data.rb +7 -0
- data/lib/phonelib/version.rb +1 -1
- data/lib/validators/phone_validator.rb +6 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bbc14f23529356b7e5f1ae1f8d189e7b586aa44
|
4
|
+
data.tar.gz: 96bb81f6b1a68d873452ce0d16b7e305cf9254a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46baab7368eda1a4defbcb9ce688811d8dc4c13df64dad099afb104a76e1cd5eda9f1d4bc1c9c332e89147965ba94ee7d1b6cdfd1ec4c2004aca91d7f2a7479d
|
7
|
+
data.tar.gz: 816cf2b257288ca4173d7809fc8d3e8c1f192d50c0b6d56aa27f5392a1e15db6ab7df4c9343e491b5febaebcc99abcc3599a4e7d93ed7f9074bff7b64afea04c
|
data/README.md
CHANGED
@@ -111,7 +111,7 @@ if mixed with <tt>possible</tt> will check if number is possible for specified t
|
|
111
111
|
<tt>countries: :us</tt> or <tt>countries: [:us, :ca]</tt> - allows to validate against specific countries,
|
112
112
|
if mixed with <tt>possible</tt> will check if number is possible for specified countries
|
113
113
|
|
114
|
-
<tt>country_specifier: ->
|
114
|
+
<tt>country_specifier: :method_name</tt> or <tt>country_specifier: -> instance { instance.country.try(:upcase) }</tt> - allows to specify country for validation dynamically for each validation. Usefull when phone is stored as national number without country prefix.
|
115
115
|
|
116
116
|
<tt>extensions: false</tt> - set to perform check for phone extension to be blank
|
117
117
|
|
data/data/extended_data.dat
CHANGED
Binary file
|
data/data/phone_data.dat
CHANGED
Binary file
|
data/lib/phonelib/core.rb
CHANGED
@@ -285,6 +285,8 @@ module Phonelib
|
|
285
285
|
EXT_PREFIXES = :prefixes
|
286
286
|
# @private Extended data geo names array key
|
287
287
|
EXT_GEO_NAMES = :geo_names
|
288
|
+
# @private Extended data country names array key
|
289
|
+
EXT_COUNTRY_NAMES = :country_names
|
288
290
|
# @private Extended data timezones array key
|
289
291
|
EXT_TIMEZONES = :timezones
|
290
292
|
# @private Extended data carriers array key
|
@@ -42,6 +42,7 @@ module Phonelib
|
|
42
42
|
@geo_names = []
|
43
43
|
@timezones = []
|
44
44
|
@carriers = []
|
45
|
+
@countries = {}
|
45
46
|
|
46
47
|
run_import
|
47
48
|
end
|
@@ -57,6 +58,7 @@ module Phonelib
|
|
57
58
|
import_geocoding_data
|
58
59
|
import_timezone_data
|
59
60
|
import_carrier_data
|
61
|
+
import_country_names
|
60
62
|
save_data_file
|
61
63
|
save_extended_data_file
|
62
64
|
end
|
@@ -137,6 +139,21 @@ module Phonelib
|
|
137
139
|
:c)
|
138
140
|
end
|
139
141
|
|
142
|
+
# import country names
|
143
|
+
def import_country_names
|
144
|
+
puts 'IMPORTING COUNTRY NAMES'
|
145
|
+
|
146
|
+
require 'open-uri'
|
147
|
+
require 'csv'
|
148
|
+
io = open('http://download.geonames.org/export/dump/countryInfo.txt')
|
149
|
+
csv = CSV.new(io, {col_sep: "\t"})
|
150
|
+
csv.each do |row|
|
151
|
+
next if row[0].start_with?('#') || row[0].empty?
|
152
|
+
|
153
|
+
@countries[row[0]] = row[4]
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
140
157
|
# adds double country code flag in case country allows
|
141
158
|
def add_double_country_flag(country)
|
142
159
|
if DOUBLE_COUNTRY_CODES_COUNTRIES.include?(country[:id])
|
@@ -22,6 +22,7 @@ module Phonelib
|
|
22
22
|
extended = {
|
23
23
|
Phonelib::Core::EXT_PREFIXES => @prefixes,
|
24
24
|
Phonelib::Core::EXT_GEO_NAMES => @geo_names,
|
25
|
+
Phonelib::Core::EXT_COUNTRY_NAMES => @countries,
|
25
26
|
Phonelib::Core::EXT_TIMEZONES => @timezones,
|
26
27
|
Phonelib::Core::EXT_CARRIERS => @carriers
|
27
28
|
}
|
@@ -32,6 +32,13 @@ module Phonelib
|
|
32
32
|
Phonelib::Core::EXT_CARRIER_KEY
|
33
33
|
end
|
34
34
|
|
35
|
+
# returns valid country name
|
36
|
+
def valid_country_name
|
37
|
+
return unless valid?
|
38
|
+
|
39
|
+
Phonelib.phone_ext_data[Phonelib::Core::EXT_COUNTRY_NAMES][valid_country]
|
40
|
+
end
|
41
|
+
|
35
42
|
private
|
36
43
|
|
37
44
|
# @private get name from extended phone data by keys
|
data/lib/phonelib/version.rb
CHANGED
@@ -92,7 +92,12 @@ class PhoneValidator < ActiveModel::EachValidator
|
|
92
92
|
|
93
93
|
def specified_country(record)
|
94
94
|
return unless options[:country_specifier]
|
95
|
-
|
95
|
+
|
96
|
+
if options[:country_specifier].is_a?(Symbol)
|
97
|
+
record.send(options[:country_specifier])
|
98
|
+
else
|
99
|
+
options[:country_specifier].call(record)
|
100
|
+
end
|
96
101
|
end
|
97
102
|
|
98
103
|
# @private
|
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.27
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vadim Senderovich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|