validates_rfc 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/validates_rfc/require_a_valid_rfc_matcher.rb +45 -3
- data/lib/validates_rfc/rfc.rb +9 -2
- data/lib/validates_rfc/rfc_validator.rb +2 -1
- data/lib/validates_rfc/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc4e96fd9caa90d6dbb49d88ad36e492a35c9a27997fbc1113453f4422ea9d69
|
4
|
+
data.tar.gz: 1d3dd86f67e7873cd5463173d2ff75adeba6356bae0b69777d00ef7ae678dc76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 644dc0e7c47aa817adb05496f67ff6505010896a6723d96c4af7ea9974576dea7b27857a03f0f7bf42e0e9c3596ac6ed84dbad4c2f098150464228aad9b5b550
|
7
|
+
data.tar.gz: bdf952cb4951ca946b7afb9290e19223264376dde9d9909a8ecc0e2a1f85fd2244c05bb137f0b07fda0db62a8c423eb73c46196cf79e934c38ab417915f3b68b
|
data/CHANGELOG.md
CHANGED
@@ -10,17 +10,59 @@ module Shoulda
|
|
10
10
|
end
|
11
11
|
|
12
12
|
class RequireAValidRfcMatcher < ValidationMatcher
|
13
|
+
def initialize(attribute)
|
14
|
+
@type = :both
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
def for_company
|
19
|
+
@type = :company
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
def for_person
|
24
|
+
@type = :person
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
13
28
|
def description
|
14
|
-
|
29
|
+
case @type
|
30
|
+
when :both then 'requires a valid RFC'
|
31
|
+
when :company then 'requires a valid company RFC'
|
32
|
+
when :person then 'requires a valid person RFC'
|
33
|
+
end
|
15
34
|
end
|
16
35
|
|
17
36
|
def failure_message
|
18
|
-
|
37
|
+
case @type
|
38
|
+
when :both then 'does not require a valid RFC'
|
39
|
+
when :company then 'does not require a valid company RFC'
|
40
|
+
when :person then 'does not require a valid person RFC'
|
41
|
+
end
|
19
42
|
end
|
20
43
|
|
21
44
|
def matches?(subject)
|
22
45
|
super(subject)
|
23
|
-
|
46
|
+
|
47
|
+
case @type
|
48
|
+
when :both then check_for_both_types
|
49
|
+
when :company then check_for_company_type
|
50
|
+
when :person then check_for_person_type
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def check_for_both_types
|
57
|
+
disallows_value_of('HEGG560427MVCRRL04') && allows_value_of('DSRT850311SA3') && allows_value_of('DSR850311SA3')
|
58
|
+
end
|
59
|
+
|
60
|
+
def check_for_company_type
|
61
|
+
disallows_value_of('HEGG560427MVCRRL04') && disallows_value_of('DSRT850311SA3') && allows_value_of('DSR850311SA3')
|
62
|
+
end
|
63
|
+
|
64
|
+
def check_for_person_type
|
65
|
+
disallows_value_of('HEGG560427MVCRRL04') && allows_value_of('DSRT850311SA3') && disallows_value_of('DSR850311SA3')
|
24
66
|
end
|
25
67
|
end
|
26
68
|
end
|
data/lib/validates_rfc/rfc.rb
CHANGED
@@ -2,16 +2,23 @@
|
|
2
2
|
|
3
3
|
module ValidatesRfc
|
4
4
|
class Rfc
|
5
|
+
COMPANY_REGEX = /\A([A-ZÑ&]{3})([0-9]{2}[0-1][0-9][0-3][0-9])([A-Z0-9]{3})\z/i.freeze
|
6
|
+
PERSON_REGEX = /\A([A-ZÑ&]{4})([0-9]{2}[0-1][0-9][0-3][0-9])([A-Z0-9]{3})\z/i.freeze
|
5
7
|
REGEX = /\A([A-ZÑ&]{3,4})([0-9]{2}[0-1][0-9][0-3][0-9])([A-Z0-9]{3})\z/i.freeze
|
6
8
|
|
7
|
-
def initialize(value)
|
9
|
+
def initialize(value, type = :both)
|
8
10
|
@value = value
|
11
|
+
@type = type
|
9
12
|
end
|
10
13
|
|
11
14
|
def valid?
|
12
15
|
return true if @value.blank?
|
13
16
|
|
14
|
-
@
|
17
|
+
case @type
|
18
|
+
when :both then @value.match(REGEX)
|
19
|
+
when :person then @value.match(PERSON_REGEX)
|
20
|
+
when :company then @value.match(COMPANY_REGEX)
|
21
|
+
end
|
15
22
|
|
16
23
|
Regexp.last_match(0).present? && valid_date?(Regexp.last_match(2))
|
17
24
|
end
|