br_documents 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/br_documents/ie/ba.rb +22 -8
- data/lib/br_documents/version.rb +1 -1
- data/spec/ie/ba_spec.rb +6 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 09c9aff76a8e9f8c1174cd31046388cca186a799
|
4
|
+
data.tar.gz: b585193cc05100900597b13177920012f0c809b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8e5f19464173dc1dffceedf46bc56fa08df5a9b245d2af487183e0e6b09afa0669760c0a22316b29bec8a44110ab527f7beaf03fb50e98162970c36183df638
|
7
|
+
data.tar.gz: 16f4ed6b454c4da58866dbb976309754c2b512427238df3b7c8d55344d837ab50a5e40a2860ea41c9f0fcf3c1adaa4241d1b3f2cfd6f0d8043cda1dcbea97777
|
data/lib/br_documents/ie/ba.rb
CHANGED
@@ -16,24 +16,25 @@ module BrDocuments
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def valid_format?
|
19
|
-
valid_8_digits_format
|
19
|
+
valid_8_digits_format || valid_9_digits_format
|
20
20
|
end
|
21
21
|
|
22
22
|
def valid_9_digits_format
|
23
|
-
|
24
|
-
|
23
|
+
regex_mask_1 = /^(\d{7}\-\d{2})$|^(\d{9})$/
|
24
|
+
regex_mask_2 = /^(\d{3}\.\d{3}\.\d{3})$|^(\d{9})$/
|
25
|
+
regex_mask_1.match(@number).present? || regex_mask_2.match(@number).present?
|
25
26
|
end
|
26
27
|
|
27
28
|
def valid_8_digits_format
|
28
|
-
regex = /^(\d{
|
29
|
+
regex = /^(\d{6}\-\d{2})$|^(\d{8})$/
|
29
30
|
regex.match(@number).present?
|
30
31
|
end
|
31
32
|
|
32
33
|
def valid_digital_check?
|
33
|
-
@number.gsub!(
|
34
|
+
@number.gsub!(/[\.\/-]/, "")
|
34
35
|
|
35
36
|
weight1 = make_weight(total_size)
|
36
|
-
weight2 = make_weight(total_size-1)
|
37
|
+
weight2 = make_weight(total_size - 1)
|
37
38
|
|
38
39
|
digital_check2 = digital_check_generator(@number, weight2)
|
39
40
|
number = "#{@number[0, body_size]}#{digital_check2}"
|
@@ -50,7 +51,7 @@ module BrDocuments
|
|
50
51
|
end
|
51
52
|
|
52
53
|
def total_size
|
53
|
-
@number.gsub(
|
54
|
+
@number.gsub(/[\.\/-]/, "").length
|
54
55
|
end
|
55
56
|
|
56
57
|
def body_size
|
@@ -59,13 +60,26 @@ module BrDocuments
|
|
59
60
|
end
|
60
61
|
|
61
62
|
def digital_check_generator(number, weight)
|
62
|
-
if
|
63
|
+
if use_digital_check_mod10
|
63
64
|
generate_digital_check_mod10(number, weight)
|
64
65
|
else
|
65
66
|
generate_digital_check(number, weight)
|
66
67
|
end
|
67
68
|
end
|
68
69
|
|
70
|
+
def use_digital_check_mod10
|
71
|
+
position = position_of_the_element_to_define_module
|
72
|
+
@number[position].to_i <= 5 || @number[position].to_i == 8
|
73
|
+
end
|
74
|
+
|
75
|
+
def position_of_the_element_to_define_module
|
76
|
+
if total_size == 8
|
77
|
+
0
|
78
|
+
else
|
79
|
+
1
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
69
83
|
def generate_digital_check_mod10(values, weights)
|
70
84
|
sum = reduce_weights(values, weights)
|
71
85
|
mod = sum % 10
|
data/lib/br_documents/version.rb
CHANGED
data/spec/ie/ba_spec.rb
CHANGED
@@ -42,7 +42,7 @@ RSpec.describe BrDocuments::IE::BA do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
it "is valid with valid number" do
|
45
|
-
["
|
45
|
+
["123456-63", "61234557"].each do |number|
|
46
46
|
ie = described_class.new(number)
|
47
47
|
expect(ie).to be_valid
|
48
48
|
end
|
@@ -56,11 +56,14 @@ RSpec.describe BrDocuments::IE::BA do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
it "is valid with valid number" do
|
59
|
-
|
60
|
-
|
59
|
+
["1000003-06", "066.486.527"].each do |number|
|
60
|
+
ie = described_class.new(number)
|
61
|
+
expect(ie).to be_valid
|
62
|
+
end
|
61
63
|
end
|
62
64
|
end
|
63
65
|
|
64
66
|
include_examples "for to remove all masks", "1000003-06"
|
67
|
+
include_examples "for to remove all masks", "100.000.306"
|
65
68
|
end
|
66
69
|
end
|
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.12
|
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: 2015-
|
11
|
+
date: 2015-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|