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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17fb00c428cdddcf7bcf9253fa39ebd0c56c5dfc
4
- data.tar.gz: 871afff63d98345ca549360c3f96730b0233dfdd
3
+ metadata.gz: 0bbc14f23529356b7e5f1ae1f8d189e7b586aa44
4
+ data.tar.gz: 96bb81f6b1a68d873452ce0d16b7e305cf9254a8
5
5
  SHA512:
6
- metadata.gz: 364ac4b3ac70b75589fab797cbb1c8b492f06c44a6bda41289b4f41d5c460aa7ab1376e06ea6f713064585c33f6456f5ab02e4c77c34020baf200132330272e1
7
- data.tar.gz: fac36e5b7ab249ef88f9e43a8dd89f5090c2c02f5cebba2955044a36a217e500f5b2c568252647be773e40259b398a1f25446e7de48fe26e5621a723d16149f8
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: -> phone { phone.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.
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
 
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
@@ -1,4 +1,4 @@
1
1
  module Phonelib
2
2
  # @private
3
- VERSION = '0.6.26'
3
+ VERSION = '0.6.27'
4
4
  end
@@ -92,7 +92,12 @@ class PhoneValidator < ActiveModel::EachValidator
92
92
 
93
93
  def specified_country(record)
94
94
  return unless options[:country_specifier]
95
- options[:country_specifier].call(record)
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.26
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-10-15 00:00:00.000000000 Z
11
+ date: 2018-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake