br_documents 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -4
- data/circle.yml +1 -1
- data/lib/br_documents/cnpj_cpf/cnpj.rb +7 -9
- data/lib/br_documents/cnpj_cpf/cpf.rb +7 -9
- data/lib/br_documents/cnpj_cpf/document.rb +23 -15
- data/lib/br_documents/version.rb +1 -1
- data/spec/cnpj_cpf/cnpj_spec.rb +7 -0
- data/spec/cnpj_cpf/cpf_spec.rb +7 -0
- data/spec/spec_helper.rb +0 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f64e2139b8c0f45f67ba0d9a3faaa849cf234f2d
|
4
|
+
data.tar.gz: a334fc18af1193c28d8faff57cc2f75c0e26c5f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b7e01d7e6ac58d51dde5d7ad3a117bff65e6b2957b58c96af99b61c0c298076243681a7f9ae044ec46803830c9ef41b8c94fce81f1653265752f0a99156fc5c
|
7
|
+
data.tar.gz: 74e23ac1af71312b733e33b9793072a0c98f3b9af1e5b86e1740bcd152ef55512662ca6c75aa847d05290a16f0f2d5f332dd7cd724ec108f07bab6de345a9505
|
data/.travis.yml
CHANGED
data/circle.yml
CHANGED
@@ -5,19 +5,17 @@ module BrDocuments
|
|
5
5
|
class Cnpj
|
6
6
|
include Document
|
7
7
|
|
8
|
-
|
9
|
-
@number = number
|
10
|
-
end
|
8
|
+
private
|
11
9
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
weight14 = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
|
10
|
+
def format_regex
|
11
|
+
/^(\d{2}\.\d{3}\.\d{3}\/\d{4}-\d{2})$|^(\d{14})$/
|
12
|
+
end
|
16
13
|
|
17
|
-
|
14
|
+
def weights_for_digital_check
|
15
|
+
[[5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2], [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]]
|
18
16
|
end
|
19
17
|
|
20
|
-
def
|
18
|
+
def format_number
|
21
19
|
@number.sub(/(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})/, "\\1.\\2.\\3/\\4-\\5")
|
22
20
|
end
|
23
21
|
end
|
@@ -5,19 +5,17 @@ module BrDocuments
|
|
5
5
|
class Cpf
|
6
6
|
include Document
|
7
7
|
|
8
|
-
|
9
|
-
@number = number
|
10
|
-
end
|
8
|
+
private
|
11
9
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
weight11 = [11, 10, 9, 8, 7, 6, 5, 4, 3, 2]
|
10
|
+
def format_regex
|
11
|
+
/^(\d{3}\.\d{3}\.\d{3}-\d{2})$|^(\d{11})$/
|
12
|
+
end
|
16
13
|
|
17
|
-
|
14
|
+
def weights_for_digital_check
|
15
|
+
[[10, 9, 8, 7, 6, 5, 4, 3, 2], [11, 10, 9, 8, 7, 6, 5, 4, 3, 2]]
|
18
16
|
end
|
19
17
|
|
20
|
-
def
|
18
|
+
def format_number
|
21
19
|
@number.sub(/(\d{3})(\d{3})(\d{3})(\d{2})/, "\\1.\\2.\\3-\\4")
|
22
20
|
end
|
23
21
|
end
|
@@ -5,30 +5,38 @@ module BrDocuments
|
|
5
5
|
module Document
|
6
6
|
include Commons::Mod11
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
def initialize(number)
|
9
|
+
@number = number
|
10
|
+
end
|
11
|
+
|
12
|
+
def valid?
|
13
|
+
valid_format? && !sequence_of_equal_numbers? && valid_digital_check?
|
14
|
+
end
|
15
|
+
|
16
|
+
def formatted
|
17
|
+
valid? ? format_number : ""
|
13
18
|
end
|
14
19
|
|
15
20
|
private
|
16
|
-
|
17
|
-
|
21
|
+
|
22
|
+
def valid_format?
|
23
|
+
format_regex.match(@number).present?
|
18
24
|
end
|
19
25
|
|
20
|
-
def sequence_of_equal_numbers?
|
21
|
-
|
26
|
+
def sequence_of_equal_numbers?
|
27
|
+
number_without_mask.split("").uniq.length == 1
|
22
28
|
end
|
23
29
|
|
24
|
-
def valid_digital_check?
|
25
|
-
|
26
|
-
|
27
|
-
|
30
|
+
def valid_digital_check?
|
31
|
+
weight1, weight2 = weights_for_digital_check
|
32
|
+
|
33
|
+
digital_check1 = generate_digital_check(number_without_mask, weight1)
|
34
|
+
digital_check2 = generate_digital_check(number_without_mask, weight2)
|
35
|
+
@number[-2, 2].eql? "#{digital_check1}#{digital_check2}"
|
28
36
|
end
|
29
37
|
|
30
|
-
def
|
31
|
-
number.gsub(/[\.\/-]/, "")
|
38
|
+
def number_without_mask
|
39
|
+
@number.gsub(/[\.\/-]/, "")
|
32
40
|
end
|
33
41
|
end
|
34
42
|
end
|
data/lib/br_documents/version.rb
CHANGED
data/spec/cnpj_cpf/cnpj_spec.rb
CHANGED
@@ -6,6 +6,13 @@ describe BrDocuments::CnpjCpf::Cnpj do
|
|
6
6
|
cnpj = BrDocuments::CnpjCpf::Cnpj.new("04001155000101")
|
7
7
|
expect(cnpj.formatted).to eq "04.001.155/0001-01"
|
8
8
|
end
|
9
|
+
|
10
|
+
context "when is invalid" do
|
11
|
+
it "returns an empty string" do
|
12
|
+
cnpj = BrDocuments::CnpjCpf::Cnpj.new("123")
|
13
|
+
expect(cnpj.formatted).to eq ""
|
14
|
+
end
|
15
|
+
end
|
9
16
|
end
|
10
17
|
|
11
18
|
it "is invalid with malformed number" do
|
data/spec/cnpj_cpf/cpf_spec.rb
CHANGED
@@ -6,6 +6,13 @@ describe BrDocuments::CnpjCpf::Cpf do
|
|
6
6
|
cpf = BrDocuments::CnpjCpf::Cpf.new("11144477735")
|
7
7
|
expect(cpf.formatted).to eq "111.444.777-35"
|
8
8
|
end
|
9
|
+
|
10
|
+
context "when is invalid" do
|
11
|
+
it "returns an empty string" do
|
12
|
+
cpf = BrDocuments::CnpjCpf::Cpf.new("123")
|
13
|
+
expect(cpf.formatted).to eq ""
|
14
|
+
end
|
15
|
+
end
|
9
16
|
end
|
10
17
|
|
11
18
|
it "is invalid with malformed number" do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: br_documents
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ASSEINFO - Sistemas de Informação
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -235,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
235
235
|
version: '0'
|
236
236
|
requirements: []
|
237
237
|
rubyforge_project:
|
238
|
-
rubygems_version: 2.4.
|
238
|
+
rubygems_version: 2.4.8
|
239
239
|
signing_key:
|
240
240
|
specification_version: 4
|
241
241
|
summary: Validates brazilian documents like CPF, CNPJ and IE. It can be used with
|