br_documents 0.2.4 → 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/.github/workflows/config.yml +7 -10
- data/.rubocop.yml +17 -2
- data/Gemfile.lock +87 -48
- data/br_documents.gemspec +7 -7
- data/lib/br_documents/ie/ap.rb +8 -4
- data/lib/br_documents/ie/ba.rb +5 -5
- data/lib/br_documents/ie/pe.rb +2 -6
- data/lib/br_documents/ie/rn.rb +4 -5
- data/lib/br_documents/ie/ro.rb +6 -6
- data/lib/br_documents/suframa.rb +1 -1
- data/lib/br_documents/version.rb +1 -1
- data/lib/br_documents.rb +1 -1
- data/spec/br_documents/ie/ac_spec.rb +1 -1
- data/spec/br_documents/ie/al_spec.rb +1 -1
- data/spec/br_documents/ie/am_spec.rb +1 -1
- data/spec/br_documents/ie/ap_spec.rb +12 -5
- data/spec/br_documents/ie/ba_spec.rb +2 -2
- data/spec/br_documents/ie/ce_spec.rb +1 -1
- data/spec/br_documents/ie/df_spec.rb +1 -1
- data/spec/br_documents/ie/es_spec.rb +1 -1
- data/spec/br_documents/ie/go_spec.rb +1 -1
- data/spec/br_documents/ie/ma_spec.rb +1 -1
- data/spec/br_documents/ie/mg_spec.rb +1 -1
- data/spec/br_documents/ie/ms_spec.rb +1 -1
- data/spec/br_documents/ie/mt_spec.rb +1 -1
- data/spec/br_documents/ie/pa_spec.rb +1 -1
- data/spec/br_documents/ie/pb_spec.rb +1 -1
- data/spec/br_documents/ie/pe_spec.rb +1 -1
- data/spec/br_documents/ie/pi_spec.rb +1 -1
- data/spec/br_documents/ie/pr_spec.rb +1 -1
- data/spec/br_documents/ie/rj_spec.rb +1 -1
- data/spec/br_documents/ie/rn_spec.rb +1 -1
- data/spec/br_documents/ie/ro_spec.rb +1 -1
- data/spec/br_documents/ie/rr_spec.rb +1 -1
- data/spec/br_documents/ie/rs_spec.rb +1 -1
- data/spec/br_documents/ie/sc_spec.rb +1 -1
- data/spec/br_documents/ie/se_spec.rb +1 -1
- data/spec/br_documents/ie/sp_spec.rb +1 -1
- data/spec/br_documents/ie/to_spec.rb +1 -1
- data/spec/br_documents/ie_validator_spec.rb +1 -2
- data/spec/br_documents/suframa_validator_spec.rb +1 -1
- data/spec/spec_helper.rb +9 -2
- metadata +28 -70
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bb487d9d86c27524deb86b68a427f8eb375dee3c79b2ef3a51780e551c8eb08e
|
|
4
|
+
data.tar.gz: ab945dce20f45f5da54d47517ccb92fa51ac668932696d897f4981a915d86df8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9fe9865dc6c6b9c94988b6f67b371996fc3e287033e0587026e502606592041e8fb58088015fc084c964bde7edd297ebed756d5fb3914c065f220c4b779ef776
|
|
7
|
+
data.tar.gz: 2a7cb3d025e30a6019f7a2cec9774ef62ca7281c496187cc87f6e4e4c09ecb2c85c287e65ff8f3a89b15fa9d39eb0e9b32054688b1c5c2a8ecbddad4b41e2111
|
|
@@ -8,11 +8,11 @@ jobs:
|
|
|
8
8
|
|
|
9
9
|
steps:
|
|
10
10
|
|
|
11
|
-
- uses: actions/checkout@
|
|
11
|
+
- uses: actions/checkout@v4
|
|
12
12
|
|
|
13
13
|
- uses: ruby/setup-ruby@v1
|
|
14
14
|
with:
|
|
15
|
-
ruby-version: 3.
|
|
15
|
+
ruby-version: 3.4
|
|
16
16
|
bundler-cache: true
|
|
17
17
|
|
|
18
18
|
- run: bundle exec rubocop --display-cop-names --parallel
|
|
@@ -21,20 +21,17 @@ jobs:
|
|
|
21
21
|
runs-on: ubuntu-latest
|
|
22
22
|
|
|
23
23
|
steps:
|
|
24
|
-
- uses: actions/checkout@
|
|
24
|
+
- uses: actions/checkout@v4
|
|
25
25
|
|
|
26
26
|
- uses: ruby/setup-ruby@v1
|
|
27
27
|
with:
|
|
28
|
-
ruby-version: 3.
|
|
28
|
+
ruby-version: 3.4
|
|
29
29
|
bundler-cache: true
|
|
30
30
|
|
|
31
|
-
- run: |
|
|
32
|
-
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
|
33
|
-
chmod +x ./cc-test-reporter
|
|
31
|
+
- run: curl https://qlty.sh | sh
|
|
34
32
|
|
|
35
33
|
- run: |
|
|
36
|
-
./cc-test-reporter before-build
|
|
37
34
|
bundle exec rspec
|
|
38
|
-
|
|
35
|
+
~/.qlty/bin/qlty coverage publish coverage/coverage.json
|
|
39
36
|
env:
|
|
40
|
-
|
|
37
|
+
QLTY_COVERAGE_TOKEN: ${{secrets.QLTY_COVERAGE_TOKEN}}
|
data/.rubocop.yml
CHANGED
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
# These are the default options. The .rubocop.yml inherit and
|
|
5
5
|
# override all the default options.
|
|
6
6
|
# https://github.com/rubocop-hq/rubocop/blob/master/config/default.yml
|
|
7
|
-
|
|
7
|
+
plugins:
|
|
8
8
|
- rubocop-rails
|
|
9
9
|
- rubocop-performance
|
|
10
10
|
- rubocop-rspec
|
|
11
11
|
- rubocop-rake
|
|
12
12
|
AllCops:
|
|
13
|
-
TargetRubyVersion:
|
|
13
|
+
TargetRubyVersion: 3.4
|
|
14
14
|
DisplayCopNames: true
|
|
15
15
|
DisplayStyleGuide: true
|
|
16
16
|
NewCops: enable
|
|
@@ -75,3 +75,18 @@ Style/SpecialGlobalVars:
|
|
|
75
75
|
|
|
76
76
|
Style/WordArray:
|
|
77
77
|
EnforcedStyle: brackets
|
|
78
|
+
|
|
79
|
+
Gemspec/DevelopmentDependencies:
|
|
80
|
+
Exclude:
|
|
81
|
+
- 'br_documents.gemspec'
|
|
82
|
+
|
|
83
|
+
Rails/DeprecatedActiveModelErrorsMethods:
|
|
84
|
+
Exclude:
|
|
85
|
+
- 'spec/**/*.rb'
|
|
86
|
+
|
|
87
|
+
Naming/PredicateMethod:
|
|
88
|
+
AllowedMethods:
|
|
89
|
+
- validate_each
|
|
90
|
+
|
|
91
|
+
RSpec/VerifiedDoubleReference:
|
|
92
|
+
Enabled: false
|
data/Gemfile.lock
CHANGED
|
@@ -1,39 +1,64 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
br_documents (0.
|
|
4
|
+
br_documents (1.0.0)
|
|
5
5
|
activemodel (>= 4.0.0)
|
|
6
6
|
i18n (>= 0.6.5)
|
|
7
7
|
|
|
8
8
|
GEM
|
|
9
9
|
remote: https://rubygems.org/
|
|
10
10
|
specs:
|
|
11
|
-
activemodel (
|
|
12
|
-
activesupport (=
|
|
13
|
-
activesupport (
|
|
14
|
-
|
|
11
|
+
activemodel (8.1.2)
|
|
12
|
+
activesupport (= 8.1.2)
|
|
13
|
+
activesupport (8.1.2)
|
|
14
|
+
base64
|
|
15
|
+
bigdecimal
|
|
16
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
|
17
|
+
connection_pool (>= 2.2.5)
|
|
18
|
+
drb
|
|
15
19
|
i18n (>= 1.6, < 2)
|
|
20
|
+
json
|
|
21
|
+
logger (>= 1.4.2)
|
|
16
22
|
minitest (>= 5.1)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
23
|
+
securerandom (>= 0.3)
|
|
24
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
|
25
|
+
uri (>= 0.13.1)
|
|
26
|
+
addressable (2.8.9)
|
|
27
|
+
public_suffix (>= 2.0.2, < 8.0)
|
|
28
|
+
ast (2.4.3)
|
|
29
|
+
base64 (0.3.0)
|
|
30
|
+
bigdecimal (4.0.1)
|
|
20
31
|
byebug (11.1.3)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
concurrent-ruby (1.1.9)
|
|
32
|
+
concurrent-ruby (1.3.6)
|
|
33
|
+
connection_pool (3.0.2)
|
|
24
34
|
diff-lcs (1.4.4)
|
|
25
35
|
docile (1.4.0)
|
|
26
|
-
|
|
36
|
+
drb (2.2.3)
|
|
37
|
+
i18n (1.14.8)
|
|
27
38
|
concurrent-ruby (~> 1.0)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
39
|
+
json (2.18.1)
|
|
40
|
+
json-schema (6.1.0)
|
|
41
|
+
addressable (~> 2.8)
|
|
42
|
+
bigdecimal (>= 3.1, < 5)
|
|
43
|
+
language_server-protocol (3.17.0.5)
|
|
44
|
+
lint_roller (1.1.0)
|
|
45
|
+
logger (1.7.0)
|
|
46
|
+
mcp (0.7.1)
|
|
47
|
+
json-schema (>= 4.1)
|
|
48
|
+
minitest (6.0.2)
|
|
49
|
+
drb (~> 2.0)
|
|
50
|
+
prism (~> 1.5)
|
|
51
|
+
parallel (1.27.0)
|
|
52
|
+
parser (3.3.10.2)
|
|
31
53
|
ast (~> 2.4.1)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
54
|
+
racc
|
|
55
|
+
prism (1.9.0)
|
|
56
|
+
public_suffix (7.0.2)
|
|
57
|
+
racc (1.8.1)
|
|
58
|
+
rack (3.2.5)
|
|
59
|
+
rainbow (3.1.1)
|
|
60
|
+
rake (13.3.1)
|
|
61
|
+
regexp_parser (2.11.3)
|
|
37
62
|
rspec (3.10.0)
|
|
38
63
|
rspec-core (~> 3.10.0)
|
|
39
64
|
rspec-expectations (~> 3.10.0)
|
|
@@ -47,40 +72,54 @@ GEM
|
|
|
47
72
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
48
73
|
rspec-support (~> 3.10.0)
|
|
49
74
|
rspec-support (3.10.2)
|
|
50
|
-
rubocop (1.
|
|
75
|
+
rubocop (1.85.0)
|
|
76
|
+
json (~> 2.3)
|
|
77
|
+
language_server-protocol (~> 3.17.0.2)
|
|
78
|
+
lint_roller (~> 1.1.0)
|
|
79
|
+
mcp (~> 0.6)
|
|
51
80
|
parallel (~> 1.10)
|
|
52
|
-
parser (>= 3.
|
|
81
|
+
parser (>= 3.3.0.2)
|
|
53
82
|
rainbow (>= 2.2.2, < 4.0)
|
|
54
|
-
regexp_parser (>=
|
|
55
|
-
|
|
56
|
-
rubocop-ast (>= 1.5.0, < 2.0)
|
|
83
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
|
84
|
+
rubocop-ast (>= 1.49.0, < 2.0)
|
|
57
85
|
ruby-progressbar (~> 1.7)
|
|
58
|
-
unicode-display_width (>=
|
|
59
|
-
rubocop-ast (1.
|
|
60
|
-
parser (>= 3.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
86
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
|
87
|
+
rubocop-ast (1.49.0)
|
|
88
|
+
parser (>= 3.3.7.2)
|
|
89
|
+
prism (~> 1.7)
|
|
90
|
+
rubocop-performance (1.26.1)
|
|
91
|
+
lint_roller (~> 1.1)
|
|
92
|
+
rubocop (>= 1.75.0, < 2.0)
|
|
93
|
+
rubocop-ast (>= 1.47.1, < 2.0)
|
|
94
|
+
rubocop-rails (2.34.3)
|
|
65
95
|
activesupport (>= 4.2.0)
|
|
96
|
+
lint_roller (~> 1.1)
|
|
66
97
|
rack (>= 1.1)
|
|
67
|
-
rubocop (>= 1.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
rubocop (
|
|
72
|
-
|
|
73
|
-
|
|
98
|
+
rubocop (>= 1.75.0, < 2.0)
|
|
99
|
+
rubocop-ast (>= 1.44.0, < 2.0)
|
|
100
|
+
rubocop-rake (0.7.1)
|
|
101
|
+
lint_roller (~> 1.1)
|
|
102
|
+
rubocop (>= 1.72.1)
|
|
103
|
+
rubocop-rspec (3.9.0)
|
|
104
|
+
lint_roller (~> 1.1)
|
|
105
|
+
rubocop (~> 1.81)
|
|
106
|
+
ruby-progressbar (1.13.0)
|
|
107
|
+
securerandom (0.4.1)
|
|
74
108
|
simplecov (0.21.2)
|
|
75
109
|
docile (~> 1.1)
|
|
76
110
|
simplecov-html (~> 0.11)
|
|
77
111
|
simplecov_json_formatter (~> 0.1)
|
|
78
112
|
simplecov-html (0.12.3)
|
|
113
|
+
simplecov-json (0.2.3)
|
|
114
|
+
json
|
|
115
|
+
simplecov
|
|
79
116
|
simplecov_json_formatter (0.1.3)
|
|
80
|
-
tzinfo (2.0.
|
|
117
|
+
tzinfo (2.0.6)
|
|
81
118
|
concurrent-ruby (~> 1.0)
|
|
82
|
-
unicode-display_width (2.0
|
|
83
|
-
|
|
119
|
+
unicode-display_width (3.2.0)
|
|
120
|
+
unicode-emoji (~> 4.1)
|
|
121
|
+
unicode-emoji (4.2.0)
|
|
122
|
+
uri (1.1.1)
|
|
84
123
|
|
|
85
124
|
PLATFORMS
|
|
86
125
|
ruby
|
|
@@ -89,15 +128,15 @@ DEPENDENCIES
|
|
|
89
128
|
br_documents!
|
|
90
129
|
bundler (>= 1.3)
|
|
91
130
|
byebug (= 11.1.3)
|
|
92
|
-
codeclimate-test-reporter (>= 1.0.7)
|
|
93
131
|
rake (>= 13.0.3)
|
|
94
132
|
rspec (>= 3.10.0)
|
|
95
|
-
rubocop (
|
|
96
|
-
rubocop-performance (
|
|
97
|
-
rubocop-rails (
|
|
133
|
+
rubocop (>= 1.15.0)
|
|
134
|
+
rubocop-performance (>= 1.11.3)
|
|
135
|
+
rubocop-rails (>= 2.10.1)
|
|
98
136
|
rubocop-rake (>= 0.5.1)
|
|
99
|
-
rubocop-rspec (
|
|
137
|
+
rubocop-rspec (>= 2.3.0)
|
|
100
138
|
simplecov (>= 0.21.2)
|
|
139
|
+
simplecov-json (>= 0.2.3)
|
|
101
140
|
|
|
102
141
|
BUNDLED WITH
|
|
103
|
-
|
|
142
|
+
4.0.2
|
data/br_documents.gemspec
CHANGED
|
@@ -8,14 +8,13 @@ Gem::Specification.new do |spec|
|
|
|
8
8
|
spec.authors = ['ASSEINFO - Sistemas de Informação']
|
|
9
9
|
spec.email = ['asseinfo@asseinfo.com.br']
|
|
10
10
|
spec.description = 'Validates brazilian documents like CPF, CNPJ and IE.'
|
|
11
|
-
spec.summary = 'Validates brazilian documents like CPF, CNPJ and IE. It can be used with active record '\
|
|
11
|
+
spec.summary = 'Validates brazilian documents like CPF, CNPJ and IE. It can be used with active record ' \
|
|
12
12
|
'or just in ruby.'
|
|
13
13
|
spec.homepage = 'http://github.com/asseinfo/br_documents'
|
|
14
14
|
spec.license = 'MIT'
|
|
15
15
|
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
18
|
spec.require_paths = ['lib']
|
|
20
19
|
|
|
21
20
|
spec.add_dependency 'activemodel', '>= 4.0.0'
|
|
@@ -23,13 +22,14 @@ Gem::Specification.new do |spec|
|
|
|
23
22
|
|
|
24
23
|
spec.add_development_dependency 'bundler', '>= 1.3'
|
|
25
24
|
spec.add_development_dependency 'byebug', '11.1.3' if RUBY_VERSION >= '2.0'
|
|
26
|
-
spec.add_development_dependency 'codeclimate-test-reporter', '>= 1.0.7'
|
|
27
25
|
spec.add_development_dependency 'rake', '>= 13.0.3'
|
|
28
26
|
spec.add_development_dependency 'rspec', '>= 3.10.0'
|
|
29
|
-
spec.add_development_dependency 'rubocop', '
|
|
30
|
-
spec.add_development_dependency 'rubocop-performance', '
|
|
31
|
-
spec.add_development_dependency 'rubocop-rails', '
|
|
27
|
+
spec.add_development_dependency 'rubocop', '>= 1.15.0'
|
|
28
|
+
spec.add_development_dependency 'rubocop-performance', '>= 1.11.3'
|
|
29
|
+
spec.add_development_dependency 'rubocop-rails', '>= 2.10.1'
|
|
32
30
|
spec.add_development_dependency 'rubocop-rake', '>= 0.5.1'
|
|
33
|
-
spec.add_development_dependency 'rubocop-rspec', '
|
|
31
|
+
spec.add_development_dependency 'rubocop-rspec', '>= 2.3.0'
|
|
34
32
|
spec.add_development_dependency 'simplecov', '>= 0.21.2'
|
|
33
|
+
spec.add_development_dependency 'simplecov-json', '>= 0.2.3'
|
|
34
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
35
35
|
end
|
data/lib/br_documents/ie/ap.rb
CHANGED
|
@@ -22,7 +22,7 @@ module BrDocuments
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def valid_check_digit?
|
|
25
|
-
return false if
|
|
25
|
+
return false if number_to_calculate_digits < 3_000_001
|
|
26
26
|
|
|
27
27
|
weight = [9, 8, 7, 6, 5, 4, 3, 2]
|
|
28
28
|
detect_range_digits
|
|
@@ -33,12 +33,12 @@ module BrDocuments
|
|
|
33
33
|
|
|
34
34
|
# rubocop:disable Metrics/MethodLength
|
|
35
35
|
def detect_range_digits
|
|
36
|
-
number =
|
|
36
|
+
number = number_to_calculate_digits
|
|
37
37
|
|
|
38
|
-
if number
|
|
38
|
+
if number.between?(3_000_001, 3_017_000)
|
|
39
39
|
@p = 5
|
|
40
40
|
@d = 0
|
|
41
|
-
elsif number
|
|
41
|
+
elsif number.between?(3_017_001, 3_019_022)
|
|
42
42
|
@p = 9
|
|
43
43
|
@d = 1
|
|
44
44
|
elsif number >= 3_019_023
|
|
@@ -48,6 +48,10 @@ module BrDocuments
|
|
|
48
48
|
end
|
|
49
49
|
# rubocop:enable Metrics/MethodLength
|
|
50
50
|
|
|
51
|
+
def number_to_calculate_digits
|
|
52
|
+
@number[0, 8].to_i
|
|
53
|
+
end
|
|
54
|
+
|
|
51
55
|
def generate_check_digit(values, weights)
|
|
52
56
|
sum = reduce_weights(values, weights)
|
|
53
57
|
sum += @p
|
data/lib/br_documents/ie/ba.rb
CHANGED
|
@@ -17,7 +17,7 @@ module BrDocuments
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def valid_format?
|
|
20
|
-
valid_8_digits_format || valid_9_digits_format
|
|
20
|
+
valid_8_digits_format? || valid_9_digits_format?
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def valid_check_digit?
|
|
@@ -35,13 +35,13 @@ module BrDocuments
|
|
|
35
35
|
|
|
36
36
|
private
|
|
37
37
|
|
|
38
|
-
def valid_9_digits_format
|
|
38
|
+
def valid_9_digits_format?
|
|
39
39
|
regex_mask1 = /^(\d{7}\-\d{2})$|^(\d{9})$/
|
|
40
40
|
regex_mask2 = /^(\d{3}\.\d{3}\.\d{3})$|^(\d{9})$/
|
|
41
41
|
regex_mask1.match(@number).present? || regex_mask2.match(@number).present?
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
-
def valid_8_digits_format
|
|
44
|
+
def valid_8_digits_format?
|
|
45
45
|
regex = /^(\d{6}\-\d{2})$|^(\d{8})$/
|
|
46
46
|
regex.match(@number).present?
|
|
47
47
|
end
|
|
@@ -63,14 +63,14 @@ module BrDocuments
|
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
def digital_check_generator(number, weight)
|
|
66
|
-
if use_digital_check_mod10
|
|
66
|
+
if use_digital_check_mod10?
|
|
67
67
|
generate_check_digit_mod10(number, weight)
|
|
68
68
|
else
|
|
69
69
|
generate_check_digit(number, weight)
|
|
70
70
|
end
|
|
71
71
|
end
|
|
72
72
|
|
|
73
|
-
def use_digital_check_mod10
|
|
73
|
+
def use_digital_check_mod10?
|
|
74
74
|
position = position_of_the_element_to_define_module
|
|
75
75
|
@number[position].to_i <= 5 || @number[position].to_i == 8
|
|
76
76
|
end
|
data/lib/br_documents/ie/pe.rb
CHANGED
|
@@ -8,13 +8,9 @@ module BrDocuments
|
|
|
8
8
|
@validator = number.gsub(/[\.\/-]/, '').length <= 9 ? PE9.new(number) : PE14.new(number)
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
@validator.valid?
|
|
13
|
-
end
|
|
11
|
+
delegate :valid?, to: :@validator
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
@validator.formatted
|
|
17
|
-
end
|
|
13
|
+
delegate :formatted, to: :@validator
|
|
18
14
|
|
|
19
15
|
class PE14 < Pattern1
|
|
20
16
|
def initialize(number)
|
data/lib/br_documents/ie/rn.rb
CHANGED
|
@@ -17,26 +17,25 @@ module BrDocuments
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def valid_format?
|
|
20
|
-
valid_old_format or valid_new_format
|
|
20
|
+
valid_old_format? or valid_new_format?
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def valid_check_digit?
|
|
24
24
|
@number.gsub!(/[\.\/-]/, '')
|
|
25
25
|
|
|
26
|
-
weight =
|
|
27
|
-
@number.length.downto(2).each { |w| weight << w }
|
|
26
|
+
weight = @number.length.downto(2).map { it }
|
|
28
27
|
|
|
29
28
|
@number[-1] == generate_check_digit(@number, weight).to_s
|
|
30
29
|
end
|
|
31
30
|
|
|
32
31
|
private
|
|
33
32
|
|
|
34
|
-
def valid_old_format
|
|
33
|
+
def valid_old_format?
|
|
35
34
|
regex = /^(\d{2}\.\d{3}\.\d{3}\-\d{1})$|^(\d{9})$/
|
|
36
35
|
regex.match(@number).present?
|
|
37
36
|
end
|
|
38
37
|
|
|
39
|
-
def valid_new_format
|
|
38
|
+
def valid_new_format?
|
|
40
39
|
regex = /^(\d{2}\.\d{1}\.\d{3}\.\d{3}\-\d{1})$|^(\d{10})$/
|
|
41
40
|
regex.match(@number).present?
|
|
42
41
|
end
|
data/lib/br_documents/ie/ro.rb
CHANGED
|
@@ -17,32 +17,32 @@ module BrDocuments
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def valid_format?
|
|
20
|
-
valid_old_format or valid_new_format
|
|
20
|
+
valid_old_format? or valid_new_format?
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def valid_check_digit?
|
|
24
|
-
valid_old_digital_check or valid_new_digital_check
|
|
24
|
+
valid_old_digital_check? or valid_new_digital_check?
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
private
|
|
28
28
|
|
|
29
|
-
def valid_old_format
|
|
29
|
+
def valid_old_format?
|
|
30
30
|
regex = /^(\d{3}\.\d{5}\-\d{1})$|^(\d{9})$/
|
|
31
31
|
regex.match(@number).present?
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
def valid_new_format
|
|
34
|
+
def valid_new_format?
|
|
35
35
|
regex = /^(\d{13}\-\d{1})$|^(\d{14})$/
|
|
36
36
|
regex.match(@number).present?
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
-
def valid_old_digital_check
|
|
39
|
+
def valid_old_digital_check?
|
|
40
40
|
weight = [3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
|
|
41
41
|
remove_mask!
|
|
42
42
|
@number[-1] == generate_check_digit(@number[-6, 6], weight).to_s
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
def valid_new_digital_check
|
|
45
|
+
def valid_new_digital_check?
|
|
46
46
|
weight = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
|
|
47
47
|
remove_mask!
|
|
48
48
|
@number[-1] == generate_check_digit(@number, weight).to_s
|
data/lib/br_documents/suframa.rb
CHANGED
data/lib/br_documents/version.rb
CHANGED
data/lib/br_documents.rb
CHANGED
|
@@ -18,26 +18,33 @@ RSpec.describe BrDocuments::IE::AP do
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
it 'is invalid with invalid check number' do
|
|
21
|
-
['030123456', '030182454'
|
|
21
|
+
['030123456', '030182454'].each do |number|
|
|
22
|
+
ie = described_class.new(number)
|
|
23
|
+
expect(ie).not_to be_valid
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'is invalid if the number is less than 3_000_001' do
|
|
28
|
+
['030000000', '000000000'].each do |number|
|
|
22
29
|
ie = described_class.new(number)
|
|
23
30
|
expect(ie).not_to be_valid
|
|
24
31
|
end
|
|
25
32
|
end
|
|
26
33
|
|
|
27
34
|
it 'is valid with valid number' do
|
|
28
|
-
first_range_number = '
|
|
35
|
+
first_range_number = '030000012'
|
|
29
36
|
ie = described_class.new(first_range_number)
|
|
30
37
|
expect(ie).to be_valid
|
|
31
38
|
|
|
32
|
-
second_range_number = '
|
|
39
|
+
second_range_number = '030170011'
|
|
33
40
|
ie = described_class.new(second_range_number)
|
|
34
41
|
expect(ie).to be_valid
|
|
35
42
|
|
|
36
|
-
third_range_number = '
|
|
43
|
+
third_range_number = '030190231'
|
|
37
44
|
ie = described_class.new(third_range_number)
|
|
38
45
|
expect(ie).to be_valid
|
|
39
46
|
end
|
|
40
47
|
|
|
41
|
-
|
|
48
|
+
it_behaves_like 'for to remove all masks', '030213452'
|
|
42
49
|
end
|
|
43
50
|
end
|
|
@@ -63,7 +63,7 @@ RSpec.describe BrDocuments::IE::BA do
|
|
|
63
63
|
end
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
it_behaves_like 'for to remove all masks', '1000003-06'
|
|
67
|
+
it_behaves_like 'for to remove all masks', '100.000.306'
|
|
68
68
|
end
|
|
69
69
|
end
|
|
@@ -6,8 +6,7 @@ RSpec.describe IeValidator do
|
|
|
6
6
|
let(:record) { instance_double('model') }
|
|
7
7
|
|
|
8
8
|
before do
|
|
9
|
-
allow(record).to
|
|
10
|
-
allow(record).to receive(:errors).and_return({})
|
|
9
|
+
allow(record).to receive_messages(uf: 'SC', errors: {})
|
|
11
10
|
allow(record.errors).to receive(:messages).and_return({})
|
|
12
11
|
allow(record.errors).to receive(:add) do |attribute, error|
|
|
13
12
|
record.errors[attribute] ||= []
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
require 'simplecov'
|
|
2
|
-
|
|
2
|
+
require 'simplecov-json'
|
|
3
|
+
|
|
4
|
+
unless ENV['NO_COVERAGE']
|
|
5
|
+
SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new(
|
|
6
|
+
[SimpleCov::Formatter::HTMLFormatter, SimpleCov::Formatter::JSONFormatter]
|
|
7
|
+
)
|
|
8
|
+
SimpleCov.start
|
|
9
|
+
end
|
|
3
10
|
|
|
4
11
|
require 'bundler/setup'
|
|
5
12
|
Bundler.require(:default, :development)
|
|
6
13
|
|
|
7
14
|
require 'br_documents'
|
|
8
15
|
|
|
9
|
-
Dir["#{File.dirname(__FILE__)}/support/*.rb"].
|
|
16
|
+
Dir["#{File.dirname(__FILE__)}/support/*.rb"].each { |f| require f }
|
|
10
17
|
|
|
11
18
|
I18n.default_locale = 'pt-BR'
|
|
12
19
|
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: br_documents
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- ASSEINFO - Sistemas de Informação
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: activemodel
|
|
@@ -66,20 +65,6 @@ dependencies:
|
|
|
66
65
|
- - '='
|
|
67
66
|
- !ruby/object:Gem::Version
|
|
68
67
|
version: 11.1.3
|
|
69
|
-
- !ruby/object:Gem::Dependency
|
|
70
|
-
name: codeclimate-test-reporter
|
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
|
72
|
-
requirements:
|
|
73
|
-
- - ">="
|
|
74
|
-
- !ruby/object:Gem::Version
|
|
75
|
-
version: 1.0.7
|
|
76
|
-
type: :development
|
|
77
|
-
prerelease: false
|
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
-
requirements:
|
|
80
|
-
- - ">="
|
|
81
|
-
- !ruby/object:Gem::Version
|
|
82
|
-
version: 1.0.7
|
|
83
68
|
- !ruby/object:Gem::Dependency
|
|
84
69
|
name: rake
|
|
85
70
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -112,42 +97,42 @@ dependencies:
|
|
|
112
97
|
name: rubocop
|
|
113
98
|
requirement: !ruby/object:Gem::Requirement
|
|
114
99
|
requirements:
|
|
115
|
-
- - "
|
|
100
|
+
- - ">="
|
|
116
101
|
- !ruby/object:Gem::Version
|
|
117
102
|
version: 1.15.0
|
|
118
103
|
type: :development
|
|
119
104
|
prerelease: false
|
|
120
105
|
version_requirements: !ruby/object:Gem::Requirement
|
|
121
106
|
requirements:
|
|
122
|
-
- - "
|
|
107
|
+
- - ">="
|
|
123
108
|
- !ruby/object:Gem::Version
|
|
124
109
|
version: 1.15.0
|
|
125
110
|
- !ruby/object:Gem::Dependency
|
|
126
111
|
name: rubocop-performance
|
|
127
112
|
requirement: !ruby/object:Gem::Requirement
|
|
128
113
|
requirements:
|
|
129
|
-
- - "
|
|
114
|
+
- - ">="
|
|
130
115
|
- !ruby/object:Gem::Version
|
|
131
116
|
version: 1.11.3
|
|
132
117
|
type: :development
|
|
133
118
|
prerelease: false
|
|
134
119
|
version_requirements: !ruby/object:Gem::Requirement
|
|
135
120
|
requirements:
|
|
136
|
-
- - "
|
|
121
|
+
- - ">="
|
|
137
122
|
- !ruby/object:Gem::Version
|
|
138
123
|
version: 1.11.3
|
|
139
124
|
- !ruby/object:Gem::Dependency
|
|
140
125
|
name: rubocop-rails
|
|
141
126
|
requirement: !ruby/object:Gem::Requirement
|
|
142
127
|
requirements:
|
|
143
|
-
- - "
|
|
128
|
+
- - ">="
|
|
144
129
|
- !ruby/object:Gem::Version
|
|
145
130
|
version: 2.10.1
|
|
146
131
|
type: :development
|
|
147
132
|
prerelease: false
|
|
148
133
|
version_requirements: !ruby/object:Gem::Requirement
|
|
149
134
|
requirements:
|
|
150
|
-
- - "
|
|
135
|
+
- - ">="
|
|
151
136
|
- !ruby/object:Gem::Version
|
|
152
137
|
version: 2.10.1
|
|
153
138
|
- !ruby/object:Gem::Dependency
|
|
@@ -168,14 +153,14 @@ dependencies:
|
|
|
168
153
|
name: rubocop-rspec
|
|
169
154
|
requirement: !ruby/object:Gem::Requirement
|
|
170
155
|
requirements:
|
|
171
|
-
- - "
|
|
156
|
+
- - ">="
|
|
172
157
|
- !ruby/object:Gem::Version
|
|
173
158
|
version: 2.3.0
|
|
174
159
|
type: :development
|
|
175
160
|
prerelease: false
|
|
176
161
|
version_requirements: !ruby/object:Gem::Requirement
|
|
177
162
|
requirements:
|
|
178
|
-
- - "
|
|
163
|
+
- - ">="
|
|
179
164
|
- !ruby/object:Gem::Version
|
|
180
165
|
version: 2.3.0
|
|
181
166
|
- !ruby/object:Gem::Dependency
|
|
@@ -192,6 +177,20 @@ dependencies:
|
|
|
192
177
|
- - ">="
|
|
193
178
|
- !ruby/object:Gem::Version
|
|
194
179
|
version: 0.21.2
|
|
180
|
+
- !ruby/object:Gem::Dependency
|
|
181
|
+
name: simplecov-json
|
|
182
|
+
requirement: !ruby/object:Gem::Requirement
|
|
183
|
+
requirements:
|
|
184
|
+
- - ">="
|
|
185
|
+
- !ruby/object:Gem::Version
|
|
186
|
+
version: 0.2.3
|
|
187
|
+
type: :development
|
|
188
|
+
prerelease: false
|
|
189
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
190
|
+
requirements:
|
|
191
|
+
- - ">="
|
|
192
|
+
- !ruby/object:Gem::Version
|
|
193
|
+
version: 0.2.3
|
|
195
194
|
description: Validates brazilian documents like CPF, CNPJ and IE.
|
|
196
195
|
email:
|
|
197
196
|
- asseinfo@asseinfo.com.br
|
|
@@ -298,8 +297,8 @@ files:
|
|
|
298
297
|
homepage: http://github.com/asseinfo/br_documents
|
|
299
298
|
licenses:
|
|
300
299
|
- MIT
|
|
301
|
-
metadata:
|
|
302
|
-
|
|
300
|
+
metadata:
|
|
301
|
+
rubygems_mfa_required: 'true'
|
|
303
302
|
rdoc_options: []
|
|
304
303
|
require_paths:
|
|
305
304
|
- lib
|
|
@@ -314,49 +313,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
314
313
|
- !ruby/object:Gem::Version
|
|
315
314
|
version: '0'
|
|
316
315
|
requirements: []
|
|
317
|
-
rubygems_version: 3.
|
|
318
|
-
signing_key:
|
|
316
|
+
rubygems_version: 3.6.9
|
|
319
317
|
specification_version: 4
|
|
320
318
|
summary: Validates brazilian documents like CPF, CNPJ and IE. It can be used with
|
|
321
319
|
active record or just in ruby.
|
|
322
|
-
test_files:
|
|
323
|
-
- spec/br_documents/cnpj_cpf/cnpj_spec.rb
|
|
324
|
-
- spec/br_documents/cnpj_cpf/cpf_spec.rb
|
|
325
|
-
- spec/br_documents/cnpj_validator_spec.rb
|
|
326
|
-
- spec/br_documents/cpf_validator_spec.rb
|
|
327
|
-
- spec/br_documents/gtin_spec.rb
|
|
328
|
-
- spec/br_documents/gtin_validator_spec.rb
|
|
329
|
-
- spec/br_documents/ie/ac_spec.rb
|
|
330
|
-
- spec/br_documents/ie/al_spec.rb
|
|
331
|
-
- spec/br_documents/ie/am_spec.rb
|
|
332
|
-
- spec/br_documents/ie/ap_spec.rb
|
|
333
|
-
- spec/br_documents/ie/ba_spec.rb
|
|
334
|
-
- spec/br_documents/ie/ce_spec.rb
|
|
335
|
-
- spec/br_documents/ie/df_spec.rb
|
|
336
|
-
- spec/br_documents/ie/es_spec.rb
|
|
337
|
-
- spec/br_documents/ie/factory_spec.rb
|
|
338
|
-
- spec/br_documents/ie/go_spec.rb
|
|
339
|
-
- spec/br_documents/ie/ma_spec.rb
|
|
340
|
-
- spec/br_documents/ie/mg_spec.rb
|
|
341
|
-
- spec/br_documents/ie/ms_spec.rb
|
|
342
|
-
- spec/br_documents/ie/mt_spec.rb
|
|
343
|
-
- spec/br_documents/ie/pa_spec.rb
|
|
344
|
-
- spec/br_documents/ie/pb_spec.rb
|
|
345
|
-
- spec/br_documents/ie/pe_spec.rb
|
|
346
|
-
- spec/br_documents/ie/pi_spec.rb
|
|
347
|
-
- spec/br_documents/ie/pr_spec.rb
|
|
348
|
-
- spec/br_documents/ie/rj_spec.rb
|
|
349
|
-
- spec/br_documents/ie/rn_spec.rb
|
|
350
|
-
- spec/br_documents/ie/ro_spec.rb
|
|
351
|
-
- spec/br_documents/ie/rr_spec.rb
|
|
352
|
-
- spec/br_documents/ie/rs_spec.rb
|
|
353
|
-
- spec/br_documents/ie/sc_spec.rb
|
|
354
|
-
- spec/br_documents/ie/se_spec.rb
|
|
355
|
-
- spec/br_documents/ie/shared_examples_for_pattern1.rb
|
|
356
|
-
- spec/br_documents/ie/shared_examples_for_to_remove_all_masks.rb
|
|
357
|
-
- spec/br_documents/ie/sp_spec.rb
|
|
358
|
-
- spec/br_documents/ie/to_spec.rb
|
|
359
|
-
- spec/br_documents/ie_validator_spec.rb
|
|
360
|
-
- spec/br_documents/suframa_spec.rb
|
|
361
|
-
- spec/br_documents/suframa_validator_spec.rb
|
|
362
|
-
- spec/spec_helper.rb
|
|
320
|
+
test_files: []
|