phonelib 0.6.13 → 0.6.14

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: 001c05877dbbe82f805f2e3b59d8f62bb396d0c8
4
- data.tar.gz: b6cf5dacd263444fd64366b6157e20f5cad257e8
3
+ metadata.gz: 964115d75e8eb5754a311ab68f6ac258b2c7229d
4
+ data.tar.gz: 4ec38c67a691121dc9f0a4fa6a63ac285d3effc8
5
5
  SHA512:
6
- metadata.gz: b2380e4f7b1049878ef189425fdd2cec0e1608ef963f0c75db1a0d3e66a85db6ead922d6bf1737c6380a6ec01c694e6fd393f0eb4c7a5807731ee420dd71ebac
7
- data.tar.gz: 573732cec6ee52fa57142fef1110c0edfba82043e14c499db2863612d2f8111f270c3093ed98116c477754a92c4ab7a59d0b3b91e7beb5cbe644d9852339967c
6
+ metadata.gz: 96f9fb2295beb53be069d89e3b117f724c582f0477a8e4d233a623c579849b6a29bcca06f9744b80ebceb3e8111e0cb0e118e3aa98fc769585df7658247661ce
7
+ data.tar.gz: 4f09a4feeadd4025b72556c41e56dbcc3596fdf9302c7a01c134ac8086584c1a3f033974dd553a3f128e76f8cfdbce58ead091f96b39093a8a2dcbcae498398f
data/README.md CHANGED
@@ -108,7 +108,9 @@ Refer to [Google libphonenumber](http://code.google.com/p/libphonenumber/) for m
108
108
  <tt>types: :mobile</tt> or <tt>types: [:voip, :mobile]</tt> - allows to validate against specific phone types patterns,
109
109
  if mixed with <tt>possible</tt> will check if number is possible for specified type
110
110
 
111
- <tt>country_specifier: -> phone { phone.country.try(:upcase) }</tt> - allows to specify country for validation dynamically for each validation.
111
+ <tt>country_specifier: -> phone { phone.country.try(:upcase) }</tt> - allows to specify country for validation dynamically for each validation.
112
+
113
+ <tt>extensions: false</tt> - set to perform check for phone extension to be blank
112
114
 
113
115
  ### Basic usage
114
116
 
@@ -276,4 +278,4 @@ If you want to run including Rails environment, you need to set <tt>BUNDLE_GEMFI
276
278
  BUNDLE_GEMFILE=gemfiles/Gemfile.rails-3.2.x bundle exec rake spec
277
279
  ```
278
280
 
279
- Gemfiles can be found in <tt>gemfiles</tt> folder, there are gemfiles for Rails 3.1, 3.2 and 4.
281
+ Gemfiles can be found in <tt>gemfiles</tt> folder, there are gemfiles for Rails 3.1, 3.2, 4, 5 and 5.1.
Binary file
Binary file
@@ -147,7 +147,8 @@ module Phonelib
147
147
  # @return [Boolean] parsed phone number is valid
148
148
  def valid_for_country?(country)
149
149
  country = country.to_s.upcase
150
- @data.find do |iso2, data|
150
+ tdata = analyze(sanitized, passed_country(country))
151
+ tdata.find do |iso2, data|
151
152
  country == iso2 && data[:valid].any?
152
153
  end.is_a? Array
153
154
  end
@@ -1,4 +1,4 @@
1
1
  module Phonelib
2
2
  # @private
3
- VERSION = '0.6.13'
3
+ VERSION = '0.6.14'
4
4
  end
@@ -36,6 +36,14 @@
36
36
  # validates :mobile, phone: { possible: true, types: :mobile }
37
37
  # end
38
38
  #
39
+ # Validates that attribute does not include an extension.
40
+ # The default setting is to allow extensions
41
+ #
42
+ # class Phone < ActiveRecord::Base
43
+ # attr_accessible :number
44
+ # validates :number, phone: { extensions: false }
45
+ # end
46
+ #
39
47
  class PhoneValidator < ActiveModel::EachValidator
40
48
  # Include all core methods
41
49
  include Phonelib::Core
@@ -43,6 +51,7 @@ class PhoneValidator < ActiveModel::EachValidator
43
51
  # Validation method
44
52
  def validate_each(record, attribute, value)
45
53
  return if options[:allow_blank] && value.blank?
54
+ options[:extensions] ||= true
46
55
 
47
56
  phone = parse(value, specified_country(record))
48
57
  valid = if simple_validation?
@@ -51,6 +60,11 @@ class PhoneValidator < ActiveModel::EachValidator
51
60
  (phone_types(phone) & types).size > 0
52
61
  end
53
62
 
63
+ # We default to not-allowing extensions for fax numbers
64
+ if valid && options[:extensions] === false && !phone.extension.empty?
65
+ valid = false
66
+ end
67
+
54
68
  record.errors.add(attribute, message, options) unless valid
55
69
  end
56
70
 
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.13
4
+ version: 0.6.14
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-08-06 00:00:00.000000000 Z
11
+ date: 2017-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake