br_documents 0.1.3 → 0.2.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 +54 -0
- data/.rubocop.yml +65 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +76 -42
- data/README.md +33 -0
- data/Rakefile +3 -3
- data/br_documents.gemspec +23 -19
- data/lib/br_documents.rb +3 -3
- 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 +1 -1
- 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/suframa.rb +60 -0
- data/lib/br_documents/suframa_validator.rb +8 -0
- data/lib/br_documents/version.rb +1 -1
- data/spec/cnpj_cpf/cnpj_spec.rb +21 -21
- data/spec/cnpj_cpf/cpf_spec.rb +21 -21
- data/spec/cnpj_validator_spec.rb +12 -12
- data/spec/cpf_validator_spec.rb +12 -12
- data/spec/gtin/gtin_spec.rb +2 -2
- data/spec/gtin_validator_spec.rb +13 -13
- data/spec/ie/ac_spec.rb +16 -16
- data/spec/ie/al_spec.rb +14 -14
- data/spec/ie/am_spec.rb +16 -16
- data/spec/ie/ap_spec.rb +14 -14
- data/spec/ie/ba_spec.rb +28 -28
- data/spec/ie/ce_spec.rb +9 -9
- data/spec/ie/df_spec.rb +16 -16
- data/spec/ie/es_spec.rb +9 -9
- data/spec/ie/factory_spec.rb +88 -89
- data/spec/ie/go_spec.rb +16 -16
- data/spec/ie/ma_spec.rb +9 -9
- data/spec/ie/mg_spec.rb +16 -16
- data/spec/ie/ms_spec.rb +9 -9
- data/spec/ie/mt_spec.rb +17 -17
- data/spec/ie/pa_spec.rb +16 -16
- data/spec/ie/pb_spec.rb +9 -9
- data/spec/ie/pe_spec.rb +27 -27
- data/spec/ie/pi_spec.rb +9 -9
- data/spec/ie/pr_spec.rb +14 -14
- data/spec/ie/rj_spec.rb +16 -16
- data/spec/ie/rn_spec.rb +27 -27
- data/spec/ie/ro_spec.rb +27 -27
- data/spec/ie/rr_spec.rb +16 -16
- data/spec/ie/rs_spec.rb +16 -16
- data/spec/ie/sc_spec.rb +16 -16
- data/spec/ie/se_spec.rb +9 -9
- data/spec/ie/shared_examples_for_pattern1.rb +11 -11
- data/spec/ie/shared_examples_for_to_remove_all_masks.rb +7 -8
- data/spec/ie/sp_spec.rb +19 -19
- data/spec/ie/to_spec.rb +35 -35
- data/spec/ie_validator_spec.rb +7 -5
- data/spec/spec_helper.rb +6 -6
- data/spec/suframa/suframa_spec.rb +109 -0
- data/spec/suframa_validator_spec.rb +36 -0
- data/spec/support/utilities.rb +2 -2
- metadata +86 -23
- data/.circleci/config.yml +0 -42
data/spec/gtin/gtin_spec.rb
CHANGED
data/spec/gtin_validator_spec.rb
CHANGED
@@ -1,46 +1,46 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe GtinValidator do
|
4
|
-
let(:record) { double(
|
4
|
+
let(:record) { double('model') }
|
5
5
|
|
6
6
|
before do
|
7
7
|
allow(record).to receive(:errors).and_return([])
|
8
8
|
allow(record.errors).to receive(:messages).and_return({})
|
9
|
-
allow(record.errors).to receive(:add) do |
|
9
|
+
allow(record.errors).to receive(:add) do |attribute, error|
|
10
10
|
record.errors.messages[attribute] = [error]
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
subject { GtinValidator.new(attributes:
|
14
|
+
subject { GtinValidator.new(attributes: 'gtin') }
|
15
15
|
|
16
|
-
context
|
17
|
-
before { subject.validate_each(record,
|
16
|
+
context 'when GTIN code is valid' do
|
17
|
+
before { subject.validate_each(record, 'gtin', '1243658721548') }
|
18
18
|
|
19
19
|
it "doesn't add errors in model" do
|
20
20
|
expect(record.errors.messages).to be_empty
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
context
|
25
|
-
before { subject.validate_each(record,
|
24
|
+
context 'when GTIN is blank' do
|
25
|
+
before { subject.validate_each(record, 'gtin', '') }
|
26
26
|
|
27
27
|
it "doesn't add errors in model" do
|
28
28
|
expect(record.errors.messages).to be_empty
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
context
|
33
|
-
before { subject.validate_each(record,
|
32
|
+
context 'when GTIN is nil' do
|
33
|
+
before { subject.validate_each(record, 'gtin', nil) }
|
34
34
|
|
35
35
|
it "doesn't add errors in model" do
|
36
36
|
expect(record.errors.messages).to be_empty
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
context
|
41
|
-
before { subject.validate_each(record,
|
40
|
+
context 'when GTIN is invalid' do
|
41
|
+
before { subject.validate_each(record, 'gtin', '253667853') }
|
42
42
|
|
43
|
-
it
|
43
|
+
it 'adds errors in model' do
|
44
44
|
expect(record.errors.messages).to include 'gtin' => [:invalid]
|
45
45
|
end
|
46
46
|
end
|
data/spec/ie/ac_spec.rb
CHANGED
@@ -1,43 +1,43 @@
|
|
1
|
-
require
|
2
|
-
require_relative
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative 'shared_examples_for_to_remove_all_masks'
|
3
3
|
|
4
4
|
RSpec.describe BrDocuments::IE::AC do
|
5
|
-
describe
|
6
|
-
it
|
7
|
-
ie = described_class.new(
|
8
|
-
expect(ie.formatted).to eq
|
5
|
+
describe '#formatted' do
|
6
|
+
it 'returns a formatted ie' do
|
7
|
+
ie = described_class.new('1234567890123')
|
8
|
+
expect(ie.formatted).to eq '12.345.678/901-23'
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
describe
|
13
|
-
it
|
14
|
-
[
|
12
|
+
describe '#valid?' do
|
13
|
+
it 'is invalid with malformed number' do
|
14
|
+
['01.448.52/88.91-50', '01.278.704/5555-7', '01.AB7.904/028-50'].each do |number|
|
15
15
|
ie = described_class.new(number)
|
16
16
|
expect(ie).to_not be_valid
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
21
|
-
[
|
20
|
+
it 'is invalid with length different to 13' do
|
21
|
+
['1234567890', '123456789012'].each do |number|
|
22
22
|
ie = described_class.new(number)
|
23
23
|
expect(ie).to_not be_valid
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
28
|
-
[
|
27
|
+
it 'is invalid with invalid check number' do
|
28
|
+
['0135184641523', '0172567054082'].each do |number|
|
29
29
|
ie = described_class.new(number)
|
30
30
|
expect(ie).to_not be_valid
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
it
|
35
|
-
[
|
34
|
+
it 'is valid with valid number' do
|
35
|
+
['0182235562573', '0104754560901'].each do |number|
|
36
36
|
ie = described_class.new(number)
|
37
37
|
expect(ie).to be_valid
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
include_examples
|
41
|
+
include_examples 'for to remove all masks', '01.047.545/609-01'
|
42
42
|
end
|
43
43
|
end
|
data/spec/ie/al_spec.rb
CHANGED
@@ -1,36 +1,36 @@
|
|
1
|
-
require
|
2
|
-
require_relative
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative 'shared_examples_for_to_remove_all_masks'
|
3
3
|
|
4
4
|
describe BrDocuments::IE::AL do
|
5
|
-
describe
|
6
|
-
it
|
7
|
-
ie = described_class.new(
|
8
|
-
expect(ie.formatted).to eq
|
5
|
+
describe '#formatted' do
|
6
|
+
it 'returns a formatted ie' do
|
7
|
+
ie = described_class.new('123456789')
|
8
|
+
expect(ie.formatted).to eq '123456789'
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
describe
|
13
|
-
it
|
14
|
-
[
|
12
|
+
describe '#valid?' do
|
13
|
+
it 'is invalid with length different to 9' do
|
14
|
+
['1234567', '122345678901'].each do |number|
|
15
15
|
ie = described_class.new(number)
|
16
16
|
expect(ie).to_not be_valid
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
21
|
-
[
|
20
|
+
it 'is invalid with invalid check number' do
|
21
|
+
['245320152', '240046248'].each do |number|
|
22
22
|
ie = described_class.new(number)
|
23
23
|
expect(ie).to_not be_valid
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
28
|
-
[
|
27
|
+
it 'is valid with valid number' do
|
28
|
+
['247975494', '248466313'].each do |number|
|
29
29
|
ie = described_class.new(number)
|
30
30
|
expect(ie).to be_valid
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
include_examples
|
34
|
+
include_examples 'for to remove all masks', '248466313'
|
35
35
|
end
|
36
36
|
end
|
data/spec/ie/am_spec.rb
CHANGED
@@ -1,43 +1,43 @@
|
|
1
|
-
require
|
2
|
-
require_relative
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative 'shared_examples_for_to_remove_all_masks'
|
3
3
|
|
4
4
|
describe BrDocuments::IE::AM do
|
5
|
-
describe
|
6
|
-
it
|
7
|
-
ie = described_class.new(
|
8
|
-
expect(ie.formatted).to eq
|
5
|
+
describe '#formatted' do
|
6
|
+
it 'returns a formatted ie' do
|
7
|
+
ie = described_class.new('123456789')
|
8
|
+
expect(ie.formatted).to eq '12.345.678-9'
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
describe
|
13
|
-
it
|
14
|
-
[
|
12
|
+
describe '#valid?' do
|
13
|
+
it 'is invalid with malformed number' do
|
14
|
+
['8.535.410-60', '884.67.826-1', '13.BA9.093-6'].each do |number|
|
15
15
|
ie = described_class.new(number)
|
16
16
|
expect(ie).to_not be_valid
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
21
|
-
[
|
20
|
+
it 'is invalid with length different to 9' do
|
21
|
+
['1234567', '12345678901'].each do |number|
|
22
22
|
ie = described_class.new(number)
|
23
23
|
expect(ie).to_not be_valid
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
28
|
-
[
|
27
|
+
it 'is invalid with invalid check number' do
|
28
|
+
['500085276', '886770232'].each do |number|
|
29
29
|
ie = described_class.new(number)
|
30
30
|
expect(ie).to_not be_valid
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
it
|
35
|
-
[
|
34
|
+
it 'is valid with valid number' do
|
35
|
+
['425721221', '310636396'].each do |number|
|
36
36
|
ie = described_class.new(number)
|
37
37
|
expect(ie).to be_valid
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
include_examples
|
41
|
+
include_examples 'for to remove all masks', '31.063.639-6'
|
42
42
|
end
|
43
43
|
end
|
data/spec/ie/ap_spec.rb
CHANGED
@@ -1,36 +1,36 @@
|
|
1
|
-
require
|
2
|
-
require_relative
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative 'shared_examples_for_to_remove_all_masks'
|
3
3
|
|
4
4
|
RSpec.describe BrDocuments::IE::AP do
|
5
|
-
describe
|
6
|
-
it
|
7
|
-
ie = described_class.new(
|
8
|
-
expect(ie.formatted).to eq
|
5
|
+
describe '#formatted' do
|
6
|
+
it 'returns a formatted ie' do
|
7
|
+
ie = described_class.new('123456789')
|
8
|
+
expect(ie.formatted).to eq '123456789'
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
describe
|
13
|
-
it
|
14
|
-
[
|
12
|
+
describe '#valid?' do
|
13
|
+
it 'is invalid with length different to 9' do
|
14
|
+
['1234567', '123456789012'].each do |number|
|
15
15
|
ie = described_class.new(number)
|
16
16
|
expect(ie).to_not be_valid
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
21
|
-
[
|
20
|
+
it 'is invalid with invalid check number' do
|
21
|
+
['030123456', '030182454'].each do |number|
|
22
22
|
ie = described_class.new(number)
|
23
23
|
expect(ie).to_not be_valid
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
28
|
-
[
|
27
|
+
it 'is valid with valid number' do
|
28
|
+
['030123459', '030183458', '030213452', '030213460'].each do |number|
|
29
29
|
ie = described_class.new(number)
|
30
30
|
expect(ie).to be_valid
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
include_examples
|
34
|
+
include_examples 'for to remove all masks', '030213452'
|
35
35
|
end
|
36
36
|
end
|
data/spec/ie/ba_spec.rb
CHANGED
@@ -1,69 +1,69 @@
|
|
1
|
-
require
|
2
|
-
require_relative
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative 'shared_examples_for_to_remove_all_masks'
|
3
3
|
|
4
4
|
RSpec.describe BrDocuments::IE::BA do
|
5
|
-
describe
|
6
|
-
context
|
7
|
-
it
|
8
|
-
ie = described_class.new(
|
9
|
-
expect(ie.formatted).to eq
|
5
|
+
describe '#formatted' do
|
6
|
+
context 'when having 8 digits' do
|
7
|
+
it 'returns a formatted ie' do
|
8
|
+
ie = described_class.new('12345678')
|
9
|
+
expect(ie.formatted).to eq '123456-78'
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
context
|
14
|
-
it
|
15
|
-
ie = described_class.new(
|
16
|
-
expect(ie.formatted).to eq
|
13
|
+
context 'when having 9 digits' do
|
14
|
+
it 'returns a formatted ie' do
|
15
|
+
ie = described_class.new('123456789')
|
16
|
+
expect(ie.formatted).to eq '1234567-89'
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
describe
|
22
|
-
it
|
23
|
-
[
|
21
|
+
describe '#valid?' do
|
22
|
+
it 'is invalid with malformed number' do
|
23
|
+
['82.060.187.373', '528843171-72', 'AD402552219'].each do |number|
|
24
24
|
ie = described_class.new(number)
|
25
25
|
expect(ie).to_not be_valid
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
30
|
-
[
|
29
|
+
it 'is invalid with length different to 8 or 9' do
|
30
|
+
['1234567', '1234567890'].each do |number|
|
31
31
|
ie = described_class.new(number)
|
32
32
|
expect(ie).to_not be_valid
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
context
|
37
|
-
it
|
38
|
-
[
|
36
|
+
context 'when having 8 digits' do
|
37
|
+
it 'is invalid with invalid check number' do
|
38
|
+
['12345682', '61934523', '39034325'].each do |number|
|
39
39
|
ie = described_class.new(number)
|
40
40
|
expect(ie).to_not be_valid
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
it
|
45
|
-
[
|
44
|
+
it 'is valid with valid number' do
|
45
|
+
['123456-63', '61234557'].each do |number|
|
46
46
|
ie = described_class.new(number)
|
47
47
|
expect(ie).to be_valid
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
context
|
53
|
-
it
|
54
|
-
ie = described_class.new(
|
52
|
+
context 'when having 9 digits' do
|
53
|
+
it 'is invalid with invalid check number' do
|
54
|
+
ie = described_class.new('100052398')
|
55
55
|
expect(ie).to_not be_valid
|
56
56
|
end
|
57
57
|
|
58
|
-
it
|
59
|
-
[
|
58
|
+
it 'is valid with valid number' do
|
59
|
+
['1000003-06', '066.486.527'].each do |number|
|
60
60
|
ie = described_class.new(number)
|
61
61
|
expect(ie).to be_valid
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
include_examples
|
67
|
-
include_examples
|
66
|
+
include_examples 'for to remove all masks', '1000003-06'
|
67
|
+
include_examples 'for to remove all masks', '100.000.306'
|
68
68
|
end
|
69
69
|
end
|
data/spec/ie/ce_spec.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
require
|
2
|
-
require_relative
|
3
|
-
require_relative
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative 'shared_examples_for_pattern1'
|
3
|
+
require_relative 'shared_examples_for_to_remove_all_masks'
|
4
4
|
|
5
5
|
describe BrDocuments::IE::CE do
|
6
|
-
describe
|
7
|
-
it
|
8
|
-
ie = described_class.new(
|
9
|
-
expect(ie.formatted).to eq
|
6
|
+
describe '#formatted' do
|
7
|
+
it 'returns a formatted ie' do
|
8
|
+
ie = described_class.new('123456789')
|
9
|
+
expect(ie.formatted).to eq '12345678-9'
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
it_behaves_like
|
13
|
+
it_behaves_like 'a pattern1', 'CE'
|
14
14
|
|
15
|
-
include_examples
|
15
|
+
include_examples 'for to remove all masks', '12345678-9'
|
16
16
|
end
|
data/spec/ie/df_spec.rb
CHANGED
@@ -1,43 +1,43 @@
|
|
1
|
-
require
|
2
|
-
require_relative
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative 'shared_examples_for_to_remove_all_masks'
|
3
3
|
|
4
4
|
describe BrDocuments::IE::DF do
|
5
|
-
describe
|
6
|
-
it
|
7
|
-
ie = described_class.new(
|
8
|
-
expect(ie.formatted).to eq
|
5
|
+
describe '#formatted' do
|
6
|
+
it 'returns a formatted ie' do
|
7
|
+
ie = described_class.new('1234567890123')
|
8
|
+
expect(ie.formatted).to eq '12345678901-23'
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
describe
|
13
|
-
it
|
14
|
-
[
|
12
|
+
describe '#valid?' do
|
13
|
+
it 'is invalid with malformed number' do
|
14
|
+
['070648022871-3', '07.064.802.287-13', '0AB49871799-12'].each do |number|
|
15
15
|
ie = described_class.new(number)
|
16
16
|
expect(ie).to_not be_valid
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
21
|
-
[
|
20
|
+
it 'is invalid with length different to 13' do
|
21
|
+
['1234567890', '123456789012345'].each do |number|
|
22
22
|
ie = described_class.new(number)
|
23
23
|
expect(ie).to_not be_valid
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
28
|
-
[
|
27
|
+
it 'is invalid with invalid check number' do
|
28
|
+
['0733002219945', '0733002219943'].each do |number|
|
29
29
|
ie = described_class.new(number)
|
30
30
|
expect(ie).to_not be_valid
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
it
|
35
|
-
[
|
34
|
+
it 'is valid with valid number' do
|
35
|
+
['0746069399231', '0784748156211'].each do |number|
|
36
36
|
ie = described_class.new(number)
|
37
37
|
expect(ie).to be_valid
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
include_examples
|
41
|
+
include_examples 'for to remove all masks', '07847481562-11'
|
42
42
|
end
|
43
43
|
end
|