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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39f1732d17cd8105860805d4d92b60852edc3d45eacfabfaabcce7d59206534e
4
- data.tar.gz: 3cc233b3c06ad19ecd8338b656b4c431dbbf9fbefd690d5cafdaca3bc8beba52
3
+ metadata.gz: e8ee7ec31e4cdea5fc2ca08ac030daaaf14b9a6cce9f896385424fe13feb3149
4
+ data.tar.gz: 6d8e71d9c7fa882a572dace34f7f16cc03cc2606f417b84319073b3ad7d9d281
5
5
  SHA512:
6
- metadata.gz: '09a757e6e350ca621199e08bf72d6b5019a4981baa66eb36c57bb012281323b9645236aeacc9778f321828f24e9adb9fd3841605ba6007ab480e0e6fd61055e7'
7
- data.tar.gz: e2876496d1a4e18a0ea7c0b6c275fd0ff99e511b50cc1f9c237b4dbbcc90debecff288a818ce9f291591230ae4966db0f82557d253425734e1e9a58a7e78d852
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 (0.1.0)
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.4.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
- sum = multiply_and_sum([5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2], number)
57
- digit_verifier(sum % 11).to_s
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
- sum = multiply_and_sum([6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2], "#{number}#{first_digit_verifier}")
62
- digit_verifier(sum % 11).to_s
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
- multiplied = []
67
- number.scan(/\d{1}/).each_with_index { |e, i| multiplied[i] = e.to_i * array[i] }
68
- multiplied.inject { |s, e| s + e }
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(rest)
72
- rest < 2 ? 0 : 11 - rest
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  class ValidatesIdentity
4
4
  module BrCnpj
5
- VERSION = '0.1.0'
5
+ VERSION = '1.0.0'
6
6
  end
7
7
  end
@@ -9,6 +9,6 @@ class ValidatesIdentity
9
9
  end
10
10
  end
11
11
 
12
- ValidatesIdentity.register_identity_type('BR_CNPJ', ValidatesIdentity::BrCnpj::Validator)
13
- ValidatesIdentity::ShouldaMatchers.register_allowed_values('BR_CNPJ', %w[51.114.450/0001-46 89905757000138])
14
- ValidatesIdentity::ShouldaMatchers.register_disallowed_values('BR_CNPJ', %w[123456 51.114.450/0001-56])
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: 0.1.0
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-26 00:00:00.000000000 Z
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: '0'
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: '0'
40
+ version: 0.5.0
41
41
  description:
42
42
  email:
43
43
  - plribeiro3000@gmail.com