drexed-validators 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/validators/telephone_validator.rb +1 -21
- data/drexed-validators.gemspec +1 -1
- data/lib/drexed/validators/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e342a938df7a08549f9ddde56b612bfb8e934f62
|
4
|
+
data.tar.gz: 7e158754ff09338c71155282cd8f918dea037390
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94534101b3f1650e32d9fe43b94a7a2fb8e615a47cd634350208edfe26ae105b5f2c7836492647007089dbca965559ed97aab47c7b7eb5aac8c358ff67119359
|
7
|
+
data.tar.gz: d796d48e577a7ab3c9e22fc8e79a12442a071a50ba2b3fc583c97fa4cb51e4499d67e7d0db76315d22591aec9c67c7169e1e1ef692cb4e71112945479969621b
|
@@ -1,27 +1,7 @@
|
|
1
1
|
class TelephoneValidator < ActiveModel::EachValidator
|
2
2
|
def validate_each(object, attribute, value)
|
3
|
-
|
4
|
-
is_number = !(formatted_value =~ /^[0-9+\(\)#\.\s\/ext-]+$/).nil?
|
5
|
-
unless is_number && validate_by_region(options[:region], formatted_value)
|
3
|
+
unless value =~ /^[0-9+\(\)#\.\s\/ext-]+$/i
|
6
4
|
object.errors[attribute] << (options[:message] || "is not formatted properly")
|
7
5
|
end
|
8
6
|
end
|
9
|
-
|
10
|
-
def validate_by_region(region, formatted_value)
|
11
|
-
if region == :north_america
|
12
|
-
valid_eleven_digit?(formatted_value) || valid_ten_digit?(formatted_value) || valid_seven_digit?(formatted_value)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def valid_seven_digit?(input)
|
17
|
-
input.length == 7 && input[0] != "0" && input[0] != "1"
|
18
|
-
end
|
19
|
-
|
20
|
-
def valid_ten_digit?(input)
|
21
|
-
input.length == 10 && input[0] != "0" && input[0] != "1" && valid_seven_digit?(input.slice(-7, 7))
|
22
|
-
end
|
23
|
-
|
24
|
-
def valid_eleven_digit?(input)
|
25
|
-
input.length == 11 && input[0] == "1" && valid_ten_digit?(input.slice(-10, 10))
|
26
|
-
end
|
27
7
|
end
|
data/drexed-validators.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: drexed-validators
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Gomez
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '10.1'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '10.1'
|
41
41
|
description: Validate commonly used attributes easily with drexed-validators
|
42
42
|
email:
|
43
43
|
- j.gomez@drexed.com
|