validates_identity-br_cnpj 0.1.0 → 1.0.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 +16 -0
- data/Gemfile.lock +3 -3
- data/lib/validates_identity/br_cnpj/validator.rb +21 -9
- data/lib/validates_identity/br_cnpj/version.rb +1 -1
- data/lib/validates_identity/br_cnpj.rb +3 -3
- data/validates_identity-br_cnpj.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8ee7ec31e4cdea5fc2ca08ac030daaaf14b9a6cce9f896385424fe13feb3149
|
4
|
+
data.tar.gz: 6d8e71d9c7fa882a572dace34f7f16cc03cc2606f417b84319073b3ad7d9d281
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 275c4ac8802dbc19881c7ba14228d4b6f5bdb3f77fbe8329b4798721c66fecfbba499aeea9ac69269d71c808bb4f757fc18c3063bdbb05bc6543000d24145927
|
7
|
+
data.tar.gz: f6cf67d9fc006f924e35d6f2c9c2cfef807209de235c6a00de25601faff2d7916e6532cb9d70d748c567f6da8b7c4787b887aed2c4e4dde95df77326b4aa49cf
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
## [1.0.0] - 2024-02-29
|
2
|
+
|
3
|
+
### Changed
|
4
|
+
|
5
|
+
- First deployable version. Ready to Production
|
6
|
+
|
7
|
+
### Changed
|
8
|
+
|
9
|
+
- Improved Code
|
10
|
+
|
11
|
+
## [0.2.0] - 2024-02-27
|
12
|
+
|
13
|
+
### Fixed
|
14
|
+
|
15
|
+
- Use new `validates_identity` public APIs
|
16
|
+
|
1
17
|
## [0.1.0] - 2024-02-26
|
2
18
|
|
3
19
|
### Added
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
validates_identity-br_cnpj (
|
4
|
+
validates_identity-br_cnpj (1.0.0)
|
5
5
|
activemodel
|
6
|
-
validates_identity
|
6
|
+
validates_identity (>= 0.5.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
@@ -107,7 +107,7 @@ GEM
|
|
107
107
|
concurrent-ruby (~> 1.0)
|
108
108
|
unicode-display_width (2.5.0)
|
109
109
|
unicode_utils (1.4.0)
|
110
|
-
validates_identity (0.
|
110
|
+
validates_identity (0.5.0)
|
111
111
|
activemodel
|
112
112
|
|
113
113
|
PLATFORMS
|
@@ -40,6 +40,12 @@ class ValidatesIdentity
|
|
40
40
|
@number ||= result[1]
|
41
41
|
end
|
42
42
|
|
43
|
+
def striped_number
|
44
|
+
return if number.nil?
|
45
|
+
|
46
|
+
@striped_number ||= number.gsub(%r{[\./-]}, '')
|
47
|
+
end
|
48
|
+
|
43
49
|
def striped_value
|
44
50
|
return if number.nil?
|
45
51
|
|
@@ -53,23 +59,29 @@ class ValidatesIdentity
|
|
53
59
|
end
|
54
60
|
|
55
61
|
def first_digit_verifier
|
56
|
-
|
57
|
-
digit_verifier(
|
62
|
+
result = multiply_and_sum([5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2], striped_number)
|
63
|
+
digit_verifier(result)
|
58
64
|
end
|
59
65
|
|
60
66
|
def second_digit_verifier
|
61
|
-
|
62
|
-
digit_verifier(
|
67
|
+
result = multiply_and_sum([6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2], "#{striped_number}#{first_digit_verifier}")
|
68
|
+
digit_verifier(result)
|
63
69
|
end
|
64
70
|
|
65
71
|
def multiply_and_sum(array, number)
|
66
|
-
|
67
|
-
number.
|
68
|
-
|
72
|
+
multiplications = []
|
73
|
+
number.each_char.with_index { |char, index| multiplications[index] = char.to_i * array[index] }
|
74
|
+
multiplications.inject(:+)
|
69
75
|
end
|
70
76
|
|
71
|
-
def digit_verifier(
|
72
|
-
|
77
|
+
def digit_verifier(value)
|
78
|
+
result = value % 11
|
79
|
+
|
80
|
+
if result >= 2
|
81
|
+
(11 - result).to_s
|
82
|
+
else
|
83
|
+
0.to_s
|
84
|
+
end
|
73
85
|
end
|
74
86
|
end
|
75
87
|
end
|
@@ -9,6 +9,6 @@ class ValidatesIdentity
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
ValidatesIdentity.
|
13
|
-
ValidatesIdentity::ShouldaMatchers.
|
14
|
-
ValidatesIdentity::ShouldaMatchers.
|
12
|
+
ValidatesIdentity.register_legal_identity_type('BR_CNPJ', ValidatesIdentity::BrCnpj::Validator)
|
13
|
+
ValidatesIdentity::ShouldaMatchers.register_legal_allowed_values('BR_CNPJ', %w[51.114.450/0001-46 89905757000138])
|
14
|
+
ValidatesIdentity::ShouldaMatchers.register_legal_disallowed_values('BR_CNPJ', %w[123456 51.114.450/0001-56])
|
@@ -29,6 +29,6 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.require_paths = ['lib']
|
30
30
|
|
31
31
|
spec.add_runtime_dependency 'activemodel'
|
32
|
-
spec.add_runtime_dependency 'validates_identity'
|
32
|
+
spec.add_runtime_dependency 'validates_identity', '>= 0.5.0'
|
33
33
|
spec.metadata['rubygems_mfa_required'] = 'true'
|
34
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validates_identity-br_cnpj
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paulo Ribeiro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.5.0
|
34
34
|
type: :runtime
|
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: 0.5.0
|
41
41
|
description:
|
42
42
|
email:
|
43
43
|
- plribeiro3000@gmail.com
|