br_documents 0.1.3 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/config.yml +40 -0
- data/.rubocop.yml +73 -0
- data/.tool-versions +1 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +79 -42
- data/README.md +33 -0
- data/Rakefile +4 -4
- data/br_documents.gemspec +26 -19
- data/lib/br_documents/cnpj_cpf/cnpj.rb +2 -2
- data/lib/br_documents/cnpj_cpf/cpf.rb +2 -2
- data/lib/br_documents/cnpj_cpf/document.rb +9 -9
- data/lib/br_documents/cnpj_validator.rb +4 -4
- data/lib/br_documents/commons/mod11.rb +1 -2
- data/lib/br_documents/commons/mod14.rb +1 -2
- data/lib/br_documents/cpf_validator.rb +4 -4
- data/lib/br_documents/{gtin/gtin.rb → gtin.rb} +3 -3
- data/lib/br_documents/gtin_validator.rb +6 -6
- data/lib/br_documents/ie/ac.rb +3 -2
- data/lib/br_documents/ie/al.rb +2 -1
- data/lib/br_documents/ie/am.rb +3 -2
- data/lib/br_documents/ie/ap.rb +20 -16
- data/lib/br_documents/ie/ba.rb +28 -25
- data/lib/br_documents/ie/base.rb +1 -1
- data/lib/br_documents/ie/ce.rb +3 -2
- data/lib/br_documents/ie/df.rb +3 -2
- data/lib/br_documents/ie/es.rb +2 -1
- data/lib/br_documents/ie/factory.rb +3 -3
- data/lib/br_documents/ie/go.rb +3 -2
- data/lib/br_documents/ie/ma.rb +2 -1
- data/lib/br_documents/ie/mg.rb +14 -17
- data/lib/br_documents/ie/ms.rb +2 -1
- data/lib/br_documents/ie/mt.rb +6 -5
- data/lib/br_documents/ie/pa.rb +3 -2
- data/lib/br_documents/ie/pattern1.rb +10 -7
- data/lib/br_documents/ie/pattern2.rb +9 -8
- data/lib/br_documents/ie/pb.rb +3 -2
- data/lib/br_documents/ie/pe.rb +10 -10
- data/lib/br_documents/ie/pi.rb +2 -1
- data/lib/br_documents/ie/pr.rb +3 -2
- data/lib/br_documents/ie/rj.rb +3 -2
- data/lib/br_documents/ie/rn.rb +19 -16
- data/lib/br_documents/ie/ro.rb +16 -13
- data/lib/br_documents/ie/rr.rb +4 -3
- data/lib/br_documents/ie/rs.rb +3 -2
- data/lib/br_documents/ie/sc.rb +3 -2
- data/lib/br_documents/ie/se.rb +3 -2
- data/lib/br_documents/ie/sp.rb +17 -14
- data/lib/br_documents/ie/to.rb +6 -5
- data/lib/br_documents/ie_validator.rb +7 -7
- data/lib/br_documents/suframa.rb +46 -0
- data/lib/br_documents/suframa_validator.rb +8 -0
- data/lib/br_documents/version.rb +1 -1
- data/lib/br_documents.rb +3 -3
- data/spec/br_documents/cnpj_cpf/cnpj_spec.rb +59 -0
- data/spec/br_documents/cnpj_cpf/cpf_spec.rb +59 -0
- data/spec/br_documents/cnpj_validator_spec.rb +36 -0
- data/spec/br_documents/cpf_validator_spec.rb +36 -0
- data/spec/{gtin → br_documents}/gtin_spec.rb +4 -4
- data/spec/{gtin_validator_spec.rb → br_documents/gtin_validator_spec.rb} +14 -14
- data/spec/br_documents/ie/ac_spec.rb +43 -0
- data/spec/br_documents/ie/al_spec.rb +36 -0
- data/spec/br_documents/ie/am_spec.rb +43 -0
- data/spec/br_documents/ie/ap_spec.rb +36 -0
- data/spec/br_documents/ie/ba_spec.rb +69 -0
- data/spec/br_documents/ie/ce_spec.rb +16 -0
- data/spec/br_documents/ie/df_spec.rb +43 -0
- data/spec/br_documents/ie/es_spec.rb +16 -0
- data/spec/br_documents/ie/factory_spec.rb +202 -0
- data/spec/br_documents/ie/go_spec.rb +43 -0
- data/spec/br_documents/ie/ma_spec.rb +16 -0
- data/spec/br_documents/ie/mg_spec.rb +43 -0
- data/spec/br_documents/ie/ms_spec.rb +16 -0
- data/spec/br_documents/ie/mt_spec.rb +49 -0
- data/spec/br_documents/ie/pa_spec.rb +43 -0
- data/spec/br_documents/ie/pb_spec.rb +16 -0
- data/spec/br_documents/ie/pe_spec.rb +62 -0
- data/spec/br_documents/ie/pi_spec.rb +16 -0
- data/spec/br_documents/ie/pr_spec.rb +36 -0
- data/spec/br_documents/ie/rj_spec.rb +43 -0
- data/spec/br_documents/ie/rn_spec.rb +62 -0
- data/spec/br_documents/ie/ro_spec.rb +62 -0
- data/spec/br_documents/ie/rr_spec.rb +43 -0
- data/spec/br_documents/ie/rs_spec.rb +41 -0
- data/spec/br_documents/ie/sc_spec.rb +43 -0
- data/spec/br_documents/ie/se_spec.rb +16 -0
- data/spec/br_documents/ie/shared_examples_for_pattern1.rb +33 -0
- data/spec/br_documents/ie/shared_examples_for_to_remove_all_masks.rb +16 -0
- data/spec/br_documents/ie/sp_spec.rb +45 -0
- data/spec/br_documents/ie/to_spec.rb +100 -0
- data/spec/{ie_validator_spec.rb → br_documents/ie_validator_spec.rb} +12 -9
- data/spec/br_documents/suframa_spec.rb +73 -0
- data/spec/br_documents/suframa_validator_spec.rb +36 -0
- data/spec/spec_helper.rb +6 -6
- data/spec/support/utilities.rb +2 -2
- metadata +177 -99
- data/.circleci/config.yml +0 -42
- data/spec/cnpj_cpf/cnpj_spec.rb +0 -59
- data/spec/cnpj_cpf/cpf_spec.rb +0 -59
- data/spec/cnpj_validator_spec.rb +0 -36
- data/spec/cpf_validator_spec.rb +0 -36
- data/spec/ie/ac_spec.rb +0 -43
- data/spec/ie/al_spec.rb +0 -36
- data/spec/ie/am_spec.rb +0 -43
- data/spec/ie/ap_spec.rb +0 -36
- data/spec/ie/ba_spec.rb +0 -69
- data/spec/ie/ce_spec.rb +0 -16
- data/spec/ie/df_spec.rb +0 -43
- data/spec/ie/es_spec.rb +0 -16
- data/spec/ie/factory_spec.rb +0 -203
- data/spec/ie/go_spec.rb +0 -43
- data/spec/ie/ma_spec.rb +0 -16
- data/spec/ie/mg_spec.rb +0 -43
- data/spec/ie/ms_spec.rb +0 -16
- data/spec/ie/mt_spec.rb +0 -44
- data/spec/ie/pa_spec.rb +0 -43
- data/spec/ie/pb_spec.rb +0 -16
- data/spec/ie/pe_spec.rb +0 -62
- data/spec/ie/pi_spec.rb +0 -16
- data/spec/ie/pr_spec.rb +0 -36
- data/spec/ie/rj_spec.rb +0 -43
- data/spec/ie/rn_spec.rb +0 -62
- data/spec/ie/ro_spec.rb +0 -62
- data/spec/ie/rr_spec.rb +0 -43
- data/spec/ie/rs_spec.rb +0 -41
- data/spec/ie/sc_spec.rb +0 -43
- data/spec/ie/se_spec.rb +0 -16
- data/spec/ie/shared_examples_for_pattern1.rb +0 -33
- data/spec/ie/shared_examples_for_to_remove_all_masks.rb +0 -17
- data/spec/ie/sp_spec.rb +0 -45
- data/spec/ie/to_spec.rb +0 -100
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72fc6e3288fa8c5e3b94ddecb5c7488f106ae4108cf9c786b71229fe42b1e9c9
|
4
|
+
data.tar.gz: a7cf947a33a61a3f467f433173598a0c8d7dee127872618b80bc5d3e88321904
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ac55324bcf44f94bad987e1100fe659b9150dec1c2d20495b73e4367c4ac65d025dbda3e48183d4ae978e1c75eebeb5149bc293ab464b823af11930f8fbba66
|
7
|
+
data.tar.gz: 687d8f399192783ed87b1b75a5cfe07d34e336dae966ee8bcb56eff11010d71c9d8404be20e3674286e8c7c4749f4ffeaab6946fee6e02f608026f966c44d65d
|
@@ -0,0 +1,40 @@
|
|
1
|
+
name: Tests
|
2
|
+
|
3
|
+
on: [push]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
linter:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
|
9
|
+
steps:
|
10
|
+
|
11
|
+
- uses: actions/checkout@v2
|
12
|
+
|
13
|
+
- uses: ruby/setup-ruby@v1
|
14
|
+
with:
|
15
|
+
ruby-version: 2.7.3
|
16
|
+
bundler-cache: true
|
17
|
+
|
18
|
+
- run: bundle exec rubocop --display-cop-names --parallel
|
19
|
+
|
20
|
+
rspec:
|
21
|
+
runs-on: ubuntu-latest
|
22
|
+
|
23
|
+
steps:
|
24
|
+
- uses: actions/checkout@v2
|
25
|
+
|
26
|
+
- uses: ruby/setup-ruby@v1
|
27
|
+
with:
|
28
|
+
ruby-version: 2.7.3
|
29
|
+
bundler-cache: true
|
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
|
34
|
+
|
35
|
+
- run: |
|
36
|
+
./cc-test-reporter before-build
|
37
|
+
bundle exec rspec
|
38
|
+
./cc-test-reporter after-build -r $CC_TEST_REPORTER_ID --exit-code $?
|
39
|
+
env:
|
40
|
+
CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}}
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# You can find more information about RuboCop pending cops policy
|
2
|
+
# https://docs.rubocop.org/rubocop/versioning.html#pending-cops
|
3
|
+
#
|
4
|
+
# These are the default options. The .rubocop.yml inherit and
|
5
|
+
# override all the default options.
|
6
|
+
# https://github.com/rubocop-hq/rubocop/blob/master/config/default.yml
|
7
|
+
require:
|
8
|
+
- rubocop-rails
|
9
|
+
- rubocop-performance
|
10
|
+
- rubocop-rspec
|
11
|
+
- rubocop-rake
|
12
|
+
AllCops:
|
13
|
+
TargetRubyVersion: 2.7.3
|
14
|
+
DisplayCopNames: true
|
15
|
+
DisplayStyleGuide: true
|
16
|
+
NewCops: enable
|
17
|
+
|
18
|
+
# Offense count: 1
|
19
|
+
# Configuration parameters: Include.
|
20
|
+
# Include: **/*.gemspec
|
21
|
+
Gemspec/RequiredRubyVersion:
|
22
|
+
Exclude:
|
23
|
+
- 'br_documents.gemspec'
|
24
|
+
|
25
|
+
# Offense count: 1
|
26
|
+
# Configuration parameters: Include.
|
27
|
+
# Include: **/*.gemspec
|
28
|
+
Gemspec/RubyVersionGlobalsUsage:
|
29
|
+
Exclude:
|
30
|
+
- 'br_documents.gemspec'
|
31
|
+
|
32
|
+
# Offense count: 1
|
33
|
+
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
|
34
|
+
Metrics/AbcSize:
|
35
|
+
Max: 20
|
36
|
+
|
37
|
+
Metrics/BlockLength:
|
38
|
+
Exclude:
|
39
|
+
- 'spec/**/*.rb'
|
40
|
+
|
41
|
+
Style/Documentation:
|
42
|
+
Enabled: false
|
43
|
+
|
44
|
+
RSpec/NamedSubject:
|
45
|
+
Enabled: false # default: true
|
46
|
+
|
47
|
+
RSpec/MultipleExpectations:
|
48
|
+
Enabled: false # default: true
|
49
|
+
|
50
|
+
RSpec/NestedGroups:
|
51
|
+
Enabled: false # default: true
|
52
|
+
|
53
|
+
Style/RegexpLiteral:
|
54
|
+
Enabled: false # default: true
|
55
|
+
|
56
|
+
Style/FrozenStringLiteralComment:
|
57
|
+
EnforcedStyle: never # default: always
|
58
|
+
|
59
|
+
# Offense count: 39
|
60
|
+
# Cop supports --auto-correct.
|
61
|
+
Style/RedundantRegexpEscape:
|
62
|
+
Enabled: false
|
63
|
+
|
64
|
+
# Offense count: 1
|
65
|
+
# Cop supports --auto-correct.
|
66
|
+
# Configuration parameters: EnforcedStyle.
|
67
|
+
# SupportedStyles: use_perl_names, use_english_names
|
68
|
+
Style/SpecialGlobalVars:
|
69
|
+
Exclude:
|
70
|
+
- 'br_documents.gemspec'
|
71
|
+
|
72
|
+
Style/WordArray:
|
73
|
+
EnforcedStyle: brackets
|
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 2.7.4
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,54 +1,86 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
br_documents (0.
|
4
|
+
br_documents (0.2.2)
|
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 (6.
|
12
|
-
activesupport (= 6.
|
13
|
-
activesupport (6.
|
11
|
+
activemodel (6.1.3.2)
|
12
|
+
activesupport (= 6.1.3.2)
|
13
|
+
activesupport (6.1.3.2)
|
14
14
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
15
|
-
i18n (>=
|
16
|
-
minitest (
|
17
|
-
tzinfo (~>
|
18
|
-
zeitwerk (~> 2.
|
19
|
-
|
15
|
+
i18n (>= 1.6, < 2)
|
16
|
+
minitest (>= 5.1)
|
17
|
+
tzinfo (~> 2.0)
|
18
|
+
zeitwerk (~> 2.3)
|
19
|
+
ast (2.4.2)
|
20
|
+
byebug (11.1.3)
|
20
21
|
codeclimate-test-reporter (1.0.7)
|
21
22
|
simplecov
|
22
|
-
concurrent-ruby (1.1.
|
23
|
-
diff-lcs (1.
|
24
|
-
docile (1.
|
25
|
-
i18n (1.
|
23
|
+
concurrent-ruby (1.1.9)
|
24
|
+
diff-lcs (1.4.4)
|
25
|
+
docile (1.4.0)
|
26
|
+
i18n (1.8.10)
|
26
27
|
concurrent-ruby (~> 1.0)
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
rspec
|
28
|
+
minitest (5.14.4)
|
29
|
+
parallel (1.20.1)
|
30
|
+
parser (3.0.1.1)
|
31
|
+
ast (~> 2.4.1)
|
32
|
+
rack (2.2.3)
|
33
|
+
rainbow (3.0.0)
|
34
|
+
rake (13.0.6)
|
35
|
+
regexp_parser (2.1.1)
|
36
|
+
rexml (3.2.5)
|
37
|
+
rspec (3.10.0)
|
38
|
+
rspec-core (~> 3.10.0)
|
39
|
+
rspec-expectations (~> 3.10.0)
|
40
|
+
rspec-mocks (~> 3.10.0)
|
41
|
+
rspec-core (3.10.1)
|
42
|
+
rspec-support (~> 3.10.0)
|
43
|
+
rspec-expectations (3.10.1)
|
37
44
|
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
-
rspec-support (~> 3.
|
39
|
-
rspec-mocks (3.
|
45
|
+
rspec-support (~> 3.10.0)
|
46
|
+
rspec-mocks (3.10.2)
|
40
47
|
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
-
rspec-support (~> 3.
|
42
|
-
rspec-support (3.
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
rspec-support (~> 3.10.0)
|
49
|
+
rspec-support (3.10.2)
|
50
|
+
rubocop (1.15.0)
|
51
|
+
parallel (~> 1.10)
|
52
|
+
parser (>= 3.0.0.0)
|
53
|
+
rainbow (>= 2.2.2, < 4.0)
|
54
|
+
regexp_parser (>= 1.8, < 3.0)
|
55
|
+
rexml
|
56
|
+
rubocop-ast (>= 1.5.0, < 2.0)
|
57
|
+
ruby-progressbar (~> 1.7)
|
58
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
59
|
+
rubocop-ast (1.7.0)
|
60
|
+
parser (>= 3.0.1.1)
|
61
|
+
rubocop-performance (1.11.4)
|
62
|
+
rubocop (>= 1.7.0, < 2.0)
|
63
|
+
rubocop-ast (>= 0.4.0)
|
64
|
+
rubocop-rails (2.10.1)
|
65
|
+
activesupport (>= 4.2.0)
|
66
|
+
rack (>= 1.1)
|
67
|
+
rubocop (>= 1.7.0, < 2.0)
|
68
|
+
rubocop-rake (0.5.1)
|
69
|
+
rubocop
|
70
|
+
rubocop-rspec (2.3.0)
|
71
|
+
rubocop (~> 1.0)
|
72
|
+
rubocop-ast (>= 1.1.0)
|
73
|
+
ruby-progressbar (1.11.0)
|
74
|
+
simplecov (0.21.2)
|
75
|
+
docile (~> 1.1)
|
76
|
+
simplecov-html (~> 0.11)
|
77
|
+
simplecov_json_formatter (~> 0.1)
|
78
|
+
simplecov-html (0.12.3)
|
79
|
+
simplecov_json_formatter (0.1.3)
|
80
|
+
tzinfo (2.0.4)
|
81
|
+
concurrent-ruby (~> 1.0)
|
82
|
+
unicode-display_width (2.0.0)
|
83
|
+
zeitwerk (2.4.2)
|
52
84
|
|
53
85
|
PLATFORMS
|
54
86
|
ruby
|
@@ -56,11 +88,16 @@ PLATFORMS
|
|
56
88
|
DEPENDENCIES
|
57
89
|
br_documents!
|
58
90
|
bundler (>= 1.3)
|
59
|
-
byebug (=
|
60
|
-
codeclimate-test-reporter
|
61
|
-
rake (>=
|
62
|
-
rspec (>= 3.
|
63
|
-
|
91
|
+
byebug (= 11.1.3)
|
92
|
+
codeclimate-test-reporter (>= 1.0.7)
|
93
|
+
rake (>= 13.0.3)
|
94
|
+
rspec (>= 3.10.0)
|
95
|
+
rubocop (~> 1.15.0)
|
96
|
+
rubocop-performance (~> 1.11.3)
|
97
|
+
rubocop-rails (~> 2.10.1)
|
98
|
+
rubocop-rake (>= 0.5.1)
|
99
|
+
rubocop-rspec (~> 2.3.0)
|
100
|
+
simplecov (>= 0.21.2)
|
64
101
|
|
65
102
|
BUNDLED WITH
|
66
|
-
1.
|
103
|
+
2.1.4
|
data/README.md
CHANGED
@@ -115,6 +115,29 @@ pj.ie = "111.111.111"
|
|
115
115
|
pj.valid? # => false
|
116
116
|
```
|
117
117
|
|
118
|
+
#### SUFRAMA
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
class Person < ActiveRecord::Base
|
122
|
+
|
123
|
+
attr_accessor :suframa
|
124
|
+
|
125
|
+
validates :suframa,
|
126
|
+
suframa: true
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
pj = Person.new
|
131
|
+
pj.suframa = "100698107"
|
132
|
+
pj.valid? # => true
|
133
|
+
|
134
|
+
pj.suframa = "10.0698.107" # with mask
|
135
|
+
pj.valid? # => true
|
136
|
+
|
137
|
+
pj.suframa = "11.1111.111"
|
138
|
+
pj.valid? # => false
|
139
|
+
```
|
140
|
+
|
118
141
|
### Ruby
|
119
142
|
|
120
143
|
#### CNPJ
|
@@ -147,6 +170,16 @@ ie.formatted # => "254.062.407"
|
|
147
170
|
ie.valid? # => true
|
148
171
|
```
|
149
172
|
|
173
|
+
#### SUFRAMA
|
174
|
+
|
175
|
+
```ruby
|
176
|
+
require "br_documents"
|
177
|
+
|
178
|
+
suframa = BrDocuments::Suframa.new("100698107")
|
179
|
+
suframa.formatted # => "10.0698.107"
|
180
|
+
suframa.valid? # => true
|
181
|
+
```
|
182
|
+
|
150
183
|
## Environment variables
|
151
184
|
|
152
185
|
The following variables are necessary to be set:
|
data/Rakefile
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'rspec/core/rake_task'
|
2
|
+
require 'bundler/gem_tasks'
|
3
3
|
|
4
4
|
task default: :spec
|
5
5
|
RSpec::Core::RakeTask.new
|
6
6
|
|
7
7
|
desc "Open an irb session preloaded class's"
|
8
|
-
task :
|
9
|
-
sh
|
8
|
+
task console: :enviroment do
|
9
|
+
sh 'irb -rubygems -I lib -r br_documents.rb'
|
10
10
|
end
|
data/br_documents.gemspec
CHANGED
@@ -1,30 +1,37 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
3
|
+
require 'br_documents/version'
|
5
4
|
|
5
|
+
# rubocop:disable Metrics/BlockLength
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'br_documents'
|
8
8
|
spec.version = BrDocuments::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.description =
|
12
|
-
spec.summary =
|
13
|
-
|
14
|
-
spec.
|
9
|
+
spec.authors = ['ASSEINFO - Sistemas de Informação']
|
10
|
+
spec.email = ['asseinfo@asseinfo.com.br']
|
11
|
+
spec.description = 'Validates brazilian documents like CPF, CNPJ and IE.'
|
12
|
+
spec.summary = 'Validates brazilian documents like CPF, CNPJ and IE. It can be used with active record '\
|
13
|
+
'or just in ruby.'
|
14
|
+
spec.homepage = 'http://github.com/asseinfo/br_documents'
|
15
|
+
spec.license = 'MIT'
|
15
16
|
|
16
17
|
spec.files = `git ls-files`.split($/)
|
17
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
20
|
+
spec.require_paths = ['lib']
|
20
21
|
|
21
|
-
spec.add_dependency
|
22
|
-
spec.add_dependency
|
22
|
+
spec.add_dependency 'activemodel', '>= 4.0.0'
|
23
|
+
spec.add_dependency 'i18n', '>= 0.6.5'
|
23
24
|
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
25
|
+
spec.add_development_dependency 'bundler', '>= 1.3'
|
26
|
+
spec.add_development_dependency 'byebug', '11.1.3' if RUBY_VERSION >= '2.0'
|
27
|
+
spec.add_development_dependency 'codeclimate-test-reporter', '>= 1.0.7'
|
28
|
+
spec.add_development_dependency 'rake', '>= 13.0.3'
|
29
|
+
spec.add_development_dependency 'rspec', '>= 3.10.0'
|
30
|
+
spec.add_development_dependency 'rubocop', '~> 1.15.0'
|
31
|
+
spec.add_development_dependency 'rubocop-performance', '~> 1.11.3'
|
32
|
+
spec.add_development_dependency 'rubocop-rails', '~> 2.10.1'
|
33
|
+
spec.add_development_dependency 'rubocop-rake', '>= 0.5.1'
|
34
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 2.3.0'
|
35
|
+
spec.add_development_dependency 'simplecov', '>= 0.21.2'
|
30
36
|
end
|
37
|
+
# rubocop:enable Metrics/BlockLength
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative 'document'
|
2
2
|
|
3
3
|
module BrDocuments
|
4
4
|
module CnpjCpf
|
@@ -16,7 +16,7 @@ module BrDocuments
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def format_number
|
19
|
-
@number.sub(/(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})/,
|
19
|
+
@number.sub(/(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})/, '\\1.\\2.\\3/\\4-\\5')
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative 'document'
|
2
2
|
|
3
3
|
module BrDocuments
|
4
4
|
module CnpjCpf
|
@@ -16,7 +16,7 @@ module BrDocuments
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def format_number
|
19
|
-
@number.sub(/(\d{3})(\d{3})(\d{3})(\d{2})/,
|
19
|
+
@number.sub(/(\d{3})(\d{3})(\d{3})(\d{2})/, '\\1.\\2.\\3-\\4')
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative '../commons/mod11'
|
2
2
|
|
3
3
|
module BrDocuments
|
4
4
|
module CnpjCpf
|
@@ -10,11 +10,11 @@ module BrDocuments
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def valid?
|
13
|
-
valid_format? && !sequence_of_equal_numbers? &&
|
13
|
+
valid_format? && !sequence_of_equal_numbers? && valid_check_digit?
|
14
14
|
end
|
15
15
|
|
16
16
|
def formatted
|
17
|
-
valid? ? format_number :
|
17
|
+
valid? ? format_number : ''
|
18
18
|
end
|
19
19
|
|
20
20
|
private
|
@@ -24,19 +24,19 @@ module BrDocuments
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def sequence_of_equal_numbers?
|
27
|
-
number_without_mask.
|
27
|
+
number_without_mask.chars.uniq.length == 1
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
30
|
+
def valid_check_digit?
|
31
31
|
weight1, weight2 = weights_for_digital_check
|
32
32
|
|
33
|
-
digital_check1 =
|
34
|
-
digital_check2 =
|
35
|
-
@number[-2, 2]
|
33
|
+
digital_check1 = generate_check_digit(number_without_mask, weight1)
|
34
|
+
digital_check2 = generate_check_digit(number_without_mask, weight2)
|
35
|
+
@number[-2, 2] == "#{digital_check1}#{digital_check2}"
|
36
36
|
end
|
37
37
|
|
38
38
|
def number_without_mask
|
39
|
-
@number.gsub(/[\.\/-]/,
|
39
|
+
@number.gsub(/[\.\/-]/, '')
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class CnpjValidator < ActiveModel::EachValidator
|
2
2
|
def validate_each(record, attribute, value)
|
3
|
-
if value.
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
return if value.blank?
|
4
|
+
|
5
|
+
cnpj = BrDocuments::CnpjCpf::Cnpj.new(value)
|
6
|
+
record.errors.add(attribute, :invalid) unless cnpj.valid?
|
7
7
|
end
|
8
8
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class CpfValidator < ActiveModel::EachValidator
|
2
2
|
def validate_each(record, attribute, value)
|
3
|
-
if value.
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
return if value.blank?
|
4
|
+
|
5
|
+
cpf = BrDocuments::CnpjCpf::Cpf.new(value)
|
6
|
+
record.errors.add(attribute, :invalid) unless cpf.valid?
|
7
7
|
end
|
8
8
|
end
|
@@ -15,14 +15,14 @@ module BrDocuments
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def valid_checksum?
|
18
|
-
numbers = @code
|
18
|
+
numbers = @code[0, @code.length - 1].chars.reverse
|
19
19
|
odd = even = 0
|
20
20
|
|
21
21
|
numbers.each_with_index do |number, i|
|
22
22
|
(i + 1).even? ? (even += number.to_i) : (odd += number.to_i * 3)
|
23
23
|
end
|
24
24
|
|
25
|
-
@code.
|
25
|
+
@code[-1].to_i == ((10 - (odd + even)) % 10)
|
26
26
|
end
|
27
27
|
end
|
28
|
-
end
|
28
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
class GtinValidator
|
1
|
+
class GtinValidator < ActiveModel::EachValidator
|
2
2
|
def validate_each(record, attribute, value)
|
3
|
-
if value.
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
return if value.blank?
|
4
|
+
|
5
|
+
gtin = BrDocuments::Gtin.new(value)
|
6
|
+
record.errors.add(attribute, :invalid) unless gtin.valid?
|
7
7
|
end
|
8
|
-
end
|
8
|
+
end
|
data/lib/br_documents/ie/ac.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative 'pattern2'
|
2
2
|
|
3
3
|
module BrDocuments
|
4
4
|
module IE
|
@@ -9,8 +9,9 @@ module BrDocuments
|
|
9
9
|
end
|
10
10
|
|
11
11
|
private
|
12
|
+
|
12
13
|
def format_ie(number)
|
13
|
-
number.sub(/(\d{2})(\d{3})(\d{3})(\d{3})(\d{2})/,
|
14
|
+
number.sub(/(\d{2})(\d{3})(\d{3})(\d{3})(\d{2})/, '\\1.\\2.\\3/\\4-\\5')
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
data/lib/br_documents/ie/al.rb
CHANGED
data/lib/br_documents/ie/am.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative 'pattern1'
|
2
2
|
|
3
3
|
module BrDocuments
|
4
4
|
module IE
|
@@ -9,8 +9,9 @@ module BrDocuments
|
|
9
9
|
end
|
10
10
|
|
11
11
|
private
|
12
|
+
|
12
13
|
def format_ie(number)
|
13
|
-
number.sub(/(\d{2})(\d{3})(\d{3})(\d{1})/,
|
14
|
+
number.sub(/(\d{2})(\d{3})(\d{3})(\d{1})/, '\\1.\\2.\\3-\\4')
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|