eac_rails_utils 0.23.4 → 0.24.0
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10597063c9780ca174f0236d4bb7a87af4b5702d0617b84406ebf613afe7a822
|
4
|
+
data.tar.gz: befada54dbc901d1d2e43d33606f1a3219fd288cf3a8d52178495e337fe4d8de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 205e2134c2f1d5b5770dff69c1ec55b87fc454a563dc0e1c01623341d9b2d6701b81f502a01efcf3772bccbef45a6405ea4040bf295d2f851874fa094a2069fe
|
7
|
+
data.tar.gz: d90285c437b1ad93874601d4077e1c1d86c3df012348860523a8bb70ae33c395fbc0cb23b0089cef75e3bc4255d59c8d3329bec4ca4004266bcae513fd12c676
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eac_rails_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.24.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- E.A.C.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bootstrap-sass
|
@@ -36,14 +36,14 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '0.
|
39
|
+
version: '0.122'
|
40
40
|
type: :runtime
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '0.
|
46
|
+
version: '0.122'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rails
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,7 +164,6 @@ files:
|
|
164
164
|
- app/helpers/eac_rails_utils/menus_helper/data_builder.rb
|
165
165
|
- app/helpers/eac_rails_utils/menus_helper/gui_builder.rb
|
166
166
|
- app/helpers/eac_rails_utils/open_graph_protocol_helper.rb
|
167
|
-
- app/validators/eac_rails_utils/cpf_validator.rb
|
168
167
|
- app/validators/eac_rails_utils/immutable_validator.rb
|
169
168
|
- app/validators/eac_rails_utils/no_presence_validator.rb
|
170
169
|
- app/validators/eac_rails_utils/uri_validator.rb
|
@@ -1,66 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module EacRailsUtils
|
4
|
-
class CpfValidator < ActiveModel::EachValidator
|
5
|
-
def validate_each(record, attribute, value)
|
6
|
-
return if Cpf.new(value).valid?
|
7
|
-
|
8
|
-
record.errors.add(
|
9
|
-
attribute,
|
10
|
-
options[:message] || 'CPF inválido (9 caracteres, somente dígitos)'
|
11
|
-
)
|
12
|
-
end
|
13
|
-
|
14
|
-
class Cpf
|
15
|
-
def initialize(input)
|
16
|
-
@input = input
|
17
|
-
end
|
18
|
-
|
19
|
-
def valid?
|
20
|
-
return false if input_invalid?
|
21
|
-
|
22
|
-
digito_verificador1_calculo == values[9] && digito_verificador2_calculo == values[10]
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
attr_reader :input
|
28
|
-
|
29
|
-
def input_invalid?
|
30
|
-
input.nil? || digits.length != 11 || digits.length != input.length || null?
|
31
|
-
end
|
32
|
-
|
33
|
-
def null?
|
34
|
-
%w[12345678909 11111111111 22222222222 33333333333 44444444444 55555555555
|
35
|
-
66666666666 77777777777 88888888888 99999999999 00000000000].member?(digits.join)
|
36
|
-
end
|
37
|
-
|
38
|
-
def digits
|
39
|
-
@digits ||= input.scan(/[0-9]/)
|
40
|
-
end
|
41
|
-
|
42
|
-
def values
|
43
|
-
@values ||= digits.collect(&:to_i)
|
44
|
-
end
|
45
|
-
|
46
|
-
def digito_verificador1_calculo
|
47
|
-
digito_verificador_calculo(9, 10)
|
48
|
-
end
|
49
|
-
|
50
|
-
def digito_verificador2_calculo
|
51
|
-
digito_verificador_calculo(10, 11)
|
52
|
-
end
|
53
|
-
|
54
|
-
def digito_verificador_calculo(valores_count, coeficiente_inicial)
|
55
|
-
s = 0
|
56
|
-
c = coeficiente_inicial
|
57
|
-
(0..valores_count - 1).each do |i|
|
58
|
-
s += values[i] * c
|
59
|
-
c -= 1
|
60
|
-
end
|
61
|
-
s -= (11 * (s / 11))
|
62
|
-
[0, 1].include?(s) ? 0 : 11 - s
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|