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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e04253c9e757257d1102c07b807fdf28cc6d8e1d
4
- data.tar.gz: 2f5da6b47ff1f7ea3b00b3658ca3e98efddd6056
3
+ metadata.gz: e342a938df7a08549f9ddde56b612bfb8e934f62
4
+ data.tar.gz: 7e158754ff09338c71155282cd8f918dea037390
5
5
  SHA512:
6
- metadata.gz: adae22c7dd4ebd7d54ec86993268abd865072f0085d6098fca1b961f74ed01bc55bbd71729d3e260708efe19c26ce943387151739bb202d09c5a7f52da73feb2
7
- data.tar.gz: 2ed443ad4cd5c1ab26e02a02837e3730b2a13eea996a96e04180e37e8d28b604174cb30dd447cf8af3236ef52306d31c5090c571b34a40cfa7ffc3ec3f872927
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
- formatted_value = value.gsub(/[\s\.\+\(\)-]*/, "")
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
@@ -19,5 +19,5 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rake", "~> 10.1"
23
23
  end
@@ -1,5 +1,5 @@
1
1
  module Drexed
2
2
  module Validators
3
- VERSION = "0.0.12"
3
+ VERSION = "0.0.13"
4
4
  end
5
5
  end
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.12
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: '0'
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: '0'
40
+ version: '10.1'
41
41
  description: Validate commonly used attributes easily with drexed-validators
42
42
  email:
43
43
  - j.gomez@drexed.com