br_documents 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f9bb58e73c2ffeeb543165040e7e6e51e21d8f1e
4
- data.tar.gz: 79b96cbdc6e69c33a6f6738f7972ab2303d887ea
3
+ metadata.gz: 805f4830ab28ec221eefcdc51b00fdfddf9bc3af
4
+ data.tar.gz: 239d97d975b9dbc6c41f2520e1db31e6d8fde10b
5
5
  SHA512:
6
- metadata.gz: 3de3927c7117bc94acbf2edbb6f235bb188e7e1782cb425c0c73c3063d217930a054d84b8708d99bc50bee53ce7242a6b86f65afdc34d9462ec6826934406703
7
- data.tar.gz: 3ad7723c2eb9c82d0f55009ae2002ca245a77b2acdce8e448377c7491f0fb24aa49f3ccaf921d88f8de4335669213a0e869ea61426ba7c26299c5e042f6aaf66
6
+ metadata.gz: 174bca0588609bb33086a8a53d86c00d2ceee75a01e704acde8e6baf656f73f9297255cb928b424327edc3619eb23e309796be5fe6bdc07692b7c4fab5c7e319
7
+ data.tar.gz: 0f4f93da74605754556aac786771804ec641d03ee6120d993c6cbcc054574b3a22fcfea5971840b6f8cdcf518cc0a9cd9fed0a8a6ba4efbf39fdcdb96818651c
data/Rakefile CHANGED
@@ -3,3 +3,8 @@ require "bundler/gem_tasks"
3
3
 
4
4
  task default: :spec
5
5
  RSpec::Core::RakeTask.new
6
+
7
+ desc "Open an irb session preloaded class's"
8
+ task :console do
9
+ sh "irb -rubygems -I lib -r br_documents.rb"
10
+ end
@@ -19,7 +19,6 @@ module BrDocuments
19
19
  def valid_digital_check?
20
20
  weight = [9, 8, 7, 6, 5, 4, 3, 2]
21
21
  detect_range_digits
22
- @number.gsub!(/\./, "")
23
22
  @number[-1].eql? generate_digital_check(@number, weight).to_s
24
23
  end
25
24
 
@@ -17,7 +17,7 @@ module BrDocuments
17
17
  end
18
18
 
19
19
  def valid_digital_check?
20
- @number.gsub!(/-/, "")
20
+ @number.gsub!(/[\.\/-]/, "")
21
21
 
22
22
  number1 = @number[0, 3] + "0" + @number[3..10]
23
23
  weight1 = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]
@@ -4,7 +4,7 @@ module BrDocuments
4
4
  module IE
5
5
  class MT < Pattern1
6
6
  def initialize(number)
7
- complete_with_zeros(number) { |completted| number = completted }
7
+ generate_zeros(number) { |zeros| number.insert(0, zeros) }
8
8
 
9
9
  super
10
10
  @mask = /^\d{4}\.?\d{3}\.?\d{3}\-?\d{1}$/
@@ -12,10 +12,10 @@ module BrDocuments
12
12
  end
13
13
 
14
14
  private
15
- def complete_with_zeros(number)
15
+ def generate_zeros(number)
16
16
  just_numbers = number.gsub(/[\.\/-]/, "")
17
17
  zeros = ("0" * 11).slice(just_numbers.length, 11)
18
- yield "#{zeros}#{number}" if block_given?
18
+ yield "#{zeros}" if block_given?
19
19
  end
20
20
 
21
21
  def format_ie(number)
@@ -19,8 +19,23 @@ module BrDocuments
19
19
  end
20
20
 
21
21
  def valid_digital_check?
22
- @number.gsub!(/[\.\/-]/, "")
23
- @number[-1].eql? generate_digital_check(@number, @weight).to_s
22
+ calculated_check_digit = generate_digital_check(only_numbers, @weight).to_s
23
+ check_digit_valid = check_digit.eql? calculated_check_digit
24
+ remove_mask_of_number if check_digit_valid
25
+
26
+ check_digit_valid
27
+ end
28
+
29
+ def check_digit
30
+ only_numbers[-1]
31
+ end
32
+
33
+ def remove_mask_of_number
34
+ @number.replace only_numbers
35
+ end
36
+
37
+ def only_numbers
38
+ @number.gsub(/[\.\/-]/, "")
24
39
  end
25
40
  end
26
41
  end
@@ -19,7 +19,7 @@ module BrDocuments
19
19
  end
20
20
 
21
21
  def valid_digital_check?
22
- @number.gsub!(/-/, "")
22
+ @number.gsub!(/[\.\/-]/, "")
23
23
 
24
24
  digital_check1 = generate_digital_check(@number, @weight1)
25
25
  digital_check2 = generate_digital_check(@number, @weight2)
@@ -5,7 +5,7 @@ module BrDocuments
5
5
  module IE
6
6
  class PE
7
7
  def initialize(number)
8
- if number.gsub(/-/, "").length <= 9
8
+ if number.gsub(/[\.\/-]/, "").length <= 9
9
9
  @validator = PE9.new(number)
10
10
  else
11
11
  @validator = PE14.new(number)
@@ -24,7 +24,7 @@ module BrDocuments
24
24
  class PE14 < Pattern1
25
25
  def initialize(number)
26
26
  super
27
- @mask = /^(\d{2}\.\d{1}\.\d{3}\.\d{7})$|^(\d{14})$/
27
+ @mask = /^(\d{2}\.\d{1}\.\d{3}\.\d{7}\-\d{1})$|^(\d{14})$/
28
28
  @weight = [5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2]
29
29
  end
30
30
 
@@ -20,17 +20,17 @@ module BrDocuments
20
20
  end
21
21
 
22
22
  def valid_old_format
23
- regex = /^(\d{2}\.\d{3}\.\d{3}\-\d{1}})$|^(\d{9})$/
23
+ regex = /^(\d{2}\.\d{3}\.\d{3}\-\d{1})$|^(\d{9})$/
24
24
  regex.match(@number).present?
25
25
  end
26
26
 
27
27
  def valid_new_format
28
- regex = /^(\d{2}\.\d{1}\.\d{3}\.\d{3}\-\d{1}})$|^(\d{10})$/
28
+ regex = /^(\d{2}\.\d{1}\.\d{3}\.\d{3}\-\d{1})$|^(\d{10})$/
29
29
  regex.match(@number).present?
30
30
  end
31
31
 
32
32
  def valid_digital_check?
33
- @number.gsub!(/\./, "")
33
+ @number.gsub!(/[\.\/-]/, "")
34
34
 
35
35
  weight = []
36
36
  @number.length.downto(2).each {|w| weight << w }
@@ -35,16 +35,19 @@ module BrDocuments
35
35
 
36
36
  def valid_old_digital_check
37
37
  weight = [3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
38
- @number.gsub!(/\./, "")
38
+ remove_mask!
39
39
  @number[-1].eql? generate_digital_check(@number[-6, 6], weight).to_s
40
40
  end
41
41
 
42
42
  def valid_new_digital_check
43
43
  weight = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
44
- @number.gsub!(/\./, "")
44
+ remove_mask!
45
45
  @number[-1].eql? generate_digital_check(@number, weight).to_s
46
46
  end
47
47
 
48
+ def remove_mask!
49
+ @number.gsub!(/[\.\/-]/, "")
50
+ end
48
51
  end
49
52
  end
50
53
  end
@@ -1,3 +1,3 @@
1
1
  module BrDocuments
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
data/spec/ie/ac_spec.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  require "spec_helper"
2
+ require_relative "shared_examples_for_to_remove_all_masks"
2
3
 
3
- describe BrDocuments::IE::AC do
4
+ RSpec.describe BrDocuments::IE::AC do
4
5
  describe "#formatted" do
5
6
  it "returns a formatted ie" do
6
- ie = BrDocuments::IE::AC.new("1234567890123")
7
+ ie = described_class.new("1234567890123")
7
8
  expect(ie.formatted).to eq "12.345.678/901-23"
8
9
  end
9
10
  end
@@ -11,30 +12,32 @@ describe BrDocuments::IE::AC do
11
12
  describe "#valid?" do
12
13
  it "is invalid with malformed number" do
13
14
  ["01.448.52/88.91-50", "01.278.704/5555-7", "01.AB7.904/028-50"].each do |number|
14
- ie = BrDocuments::IE::AC.new(number)
15
+ ie = described_class.new(number)
15
16
  expect(ie).to_not be_valid
16
17
  end
17
18
  end
18
19
 
19
20
  it "is invalid with length different to 13" do
20
21
  ["1234567890", "123456789012"].each do |number|
21
- ie = BrDocuments::IE::AC.new(number)
22
+ ie = described_class.new(number)
22
23
  expect(ie).to_not be_valid
23
24
  end
24
25
  end
25
26
 
26
27
  it "is invalid with invalid check number" do
27
28
  ["0135184641523", "0172567054082"].each do |number|
28
- ie = BrDocuments::IE::AC.new(number)
29
+ ie = described_class.new(number)
29
30
  expect(ie).to_not be_valid
30
31
  end
31
32
  end
32
33
 
33
34
  it "is valid with valid number" do
34
35
  ["0182235562573", "0104754560901"].each do |number|
35
- ie = BrDocuments::IE::AC.new(number)
36
+ ie = described_class.new(number)
36
37
  expect(ie).to be_valid
37
38
  end
38
39
  end
40
+
41
+ include_examples "for to remove all masks", "01.047.545/609-01"
39
42
  end
40
43
  end
data/spec/ie/al_spec.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  require "spec_helper"
2
+ require_relative "shared_examples_for_to_remove_all_masks"
2
3
 
3
4
  describe BrDocuments::IE::AL do
4
5
  describe "#formatted" do
5
6
  it "returns a formatted ie" do
6
- ie = BrDocuments::IE::AL.new("123456789")
7
+ ie = described_class.new("123456789")
7
8
  expect(ie.formatted).to eq "123456789"
8
9
  end
9
10
  end
@@ -11,23 +12,25 @@ describe BrDocuments::IE::AL do
11
12
  describe "#valid?" do
12
13
  it "is invalid with length different to 9" do
13
14
  ["1234567", "122345678901"].each do |number|
14
- ie = BrDocuments::IE::AL.new(number)
15
+ ie = described_class.new(number)
15
16
  expect(ie).to_not be_valid
16
17
  end
17
18
  end
18
19
 
19
20
  it "is invalid with invalid check number" do
20
21
  ["245320152", "240046248"].each do |number|
21
- ie = BrDocuments::IE::AL.new(number)
22
+ ie = described_class.new(number)
22
23
  expect(ie).to_not be_valid
23
24
  end
24
25
  end
25
26
 
26
27
  it "is valid with valid number" do
27
28
  ["247975494", "248466313"].each do |number|
28
- ie = BrDocuments::IE::AL.new(number)
29
+ ie = described_class.new(number)
29
30
  expect(ie).to be_valid
30
31
  end
31
32
  end
33
+
34
+ include_examples "for to remove all masks", "248466313"
32
35
  end
33
36
  end
data/spec/ie/am_spec.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  require "spec_helper"
2
+ require_relative "shared_examples_for_to_remove_all_masks"
2
3
 
3
4
  describe BrDocuments::IE::AM do
4
5
  describe "#formatted" do
5
6
  it "returns a formatted ie" do
6
- ie = BrDocuments::IE::AM.new("123456789")
7
+ ie = described_class.new("123456789")
7
8
  expect(ie.formatted).to eq "12.345.678-9"
8
9
  end
9
10
  end
@@ -11,30 +12,32 @@ describe BrDocuments::IE::AM do
11
12
  describe "#valid?" do
12
13
  it "is invalid with malformed number" do
13
14
  ["8.535.410-60", "884.67.826-1", "13.BA9.093-6"].each do |number|
14
- ie = BrDocuments::IE::AM.new(number)
15
+ ie = described_class.new(number)
15
16
  expect(ie).to_not be_valid
16
17
  end
17
18
  end
18
19
 
19
20
  it "is invalid with length different to 9" do
20
21
  ["1234567", "12345678901"].each do |number|
21
- ie = BrDocuments::IE::AM.new(number)
22
+ ie = described_class.new(number)
22
23
  expect(ie).to_not be_valid
23
24
  end
24
25
  end
25
26
 
26
27
  it "is invalid with invalid check number" do
27
28
  ["500085276", "886770232"].each do |number|
28
- ie = BrDocuments::IE::AM.new(number)
29
+ ie = described_class.new(number)
29
30
  expect(ie).to_not be_valid
30
31
  end
31
32
  end
32
33
 
33
34
  it "is valid with valid number" do
34
35
  ["425721221", "310636396"].each do |number|
35
- ie = BrDocuments::IE::AM.new(number)
36
+ ie = described_class.new(number)
36
37
  expect(ie).to be_valid
37
38
  end
38
39
  end
40
+
41
+ include_examples "for to remove all masks", "31.063.639-6"
39
42
  end
40
43
  end
data/spec/ie/ap_spec.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  require "spec_helper"
2
+ require_relative "shared_examples_for_to_remove_all_masks"
2
3
 
3
- describe BrDocuments::IE::AP do
4
+ RSpec.describe BrDocuments::IE::AP do
4
5
  describe "#formatted" do
5
6
  it "returns a formatted ie" do
6
- ie = BrDocuments::IE::AP.new("123456789")
7
+ ie = described_class.new("123456789")
7
8
  expect(ie.formatted).to eq "123456789"
8
9
  end
9
10
  end
@@ -11,23 +12,25 @@ describe BrDocuments::IE::AP do
11
12
  describe "#valid?" do
12
13
  it "is invalid with length different to 9" do
13
14
  ["1234567", "123456789012"].each do |number|
14
- ie = BrDocuments::IE::AP.new(number)
15
+ ie = described_class.new(number)
15
16
  expect(ie).to_not be_valid
16
17
  end
17
18
  end
18
19
 
19
20
  it "is invalid with invalid check number" do
20
21
  ["030123456", "030182454"].each do |number|
21
- ie = BrDocuments::IE::AP.new(number)
22
+ ie = described_class.new(number)
22
23
  expect(ie).to_not be_valid
23
24
  end
24
25
  end
25
26
 
26
27
  it "is valid with valid number" do
27
28
  ["030123459", "030183458", "030213452"].each do |number|
28
- ie = BrDocuments::IE::AP.new(number)
29
+ ie = described_class.new(number)
29
30
  expect(ie).to be_valid
30
31
  end
31
32
  end
33
+
34
+ include_examples "for to remove all masks", "030213452"
32
35
  end
33
36
  end
data/spec/ie/ba_spec.rb CHANGED
@@ -1,17 +1,18 @@
1
1
  require "spec_helper"
2
+ require_relative "shared_examples_for_to_remove_all_masks"
2
3
 
3
- describe BrDocuments::IE::BA do
4
+ RSpec.describe BrDocuments::IE::BA do
4
5
  describe "#formatted" do
5
6
  context "when having 8 digits" do
6
7
  it "returns a formatted ie" do
7
- ie = BrDocuments::IE::BA.new("12345678")
8
+ ie = described_class.new("12345678")
8
9
  expect(ie.formatted).to eq "123456-78"
9
10
  end
10
11
  end
11
12
 
12
13
  context "when having 9 digits" do
13
14
  it "returns a formatted ie" do
14
- ie = BrDocuments::IE::BA.new("123456789")
15
+ ie = described_class.new("123456789")
15
16
  expect(ie.formatted).to eq "1234567-89"
16
17
  end
17
18
  end
@@ -20,14 +21,14 @@ describe BrDocuments::IE::BA do
20
21
  describe "#valid?" do
21
22
  it "is invalid with malformed number" do
22
23
  ["82.060.187.373", "528843171-72", "AD402552219"].each do |number|
23
- ie = BrDocuments::IE::BA.new(number)
24
+ ie = described_class.new(number)
24
25
  expect(ie).to_not be_valid
25
26
  end
26
27
  end
27
28
 
28
29
  it "is invalid with length different to 8 or 9" do
29
30
  ["1234567", "1234567890"].each do |number|
30
- ie = BrDocuments::IE::BA.new(number)
31
+ ie = described_class.new(number)
31
32
  expect(ie).to_not be_valid
32
33
  end
33
34
  end
@@ -35,14 +36,14 @@ describe BrDocuments::IE::BA do
35
36
  context "when having 8 digits" do
36
37
  it "is invalid with invalid check number" do
37
38
  ["12345682", "61934523", "39034325"].each do |number|
38
- ie = BrDocuments::IE::BA.new(number)
39
+ ie = described_class.new(number)
39
40
  expect(ie).to_not be_valid
40
41
  end
41
42
  end
42
43
 
43
44
  it "is valid with valid number" do
44
45
  ["12345663", "61234557"].each do |number|
45
- ie = BrDocuments::IE::BA.new(number)
46
+ ie = described_class.new(number)
46
47
  expect(ie).to be_valid
47
48
  end
48
49
  end
@@ -50,14 +51,16 @@ describe BrDocuments::IE::BA do
50
51
 
51
52
  context "when having 9 digits" do
52
53
  it "is invalid with invalid check number" do
53
- ie = BrDocuments::IE::BA.new("100052398")
54
+ ie = described_class.new("100052398")
54
55
  expect(ie).to_not be_valid
55
56
  end
56
57
 
57
58
  it "is valid with valid number" do
58
- ie = BrDocuments::IE::BA.new("100000306")
59
+ ie = described_class.new("100000306")
59
60
  expect(ie).to be_valid
60
61
  end
61
62
  end
63
+
64
+ include_examples "for to remove all masks", "1000003-06"
62
65
  end
63
66
  end
data/spec/ie/ce_spec.rb CHANGED
@@ -1,13 +1,16 @@
1
1
  require "spec_helper"
2
2
  require_relative "shared_examples_for_pattern1"
3
+ require_relative "shared_examples_for_to_remove_all_masks"
3
4
 
4
5
  describe BrDocuments::IE::CE do
5
6
  describe "#formatted" do
6
7
  it "returns a formatted ie" do
7
- ie = BrDocuments::IE::CE.new("123456789")
8
+ ie = described_class.new("123456789")
8
9
  expect(ie.formatted).to eq "12345678-9"
9
10
  end
10
11
  end
11
12
 
12
13
  it_behaves_like "a pattern1", "CE"
14
+
15
+ include_examples "for to remove all masks", "12345678-9"
13
16
  end
data/spec/ie/df_spec.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  require "spec_helper"
2
+ require_relative "shared_examples_for_to_remove_all_masks"
2
3
 
3
4
  describe BrDocuments::IE::DF do
4
5
  describe "#formatted" do
5
6
  it "returns a formatted ie" do
6
- ie = BrDocuments::IE::DF.new("1234567890123")
7
+ ie = described_class.new("1234567890123")
7
8
  expect(ie.formatted).to eq "12345678901-23"
8
9
  end
9
10
  end
@@ -11,30 +12,32 @@ describe BrDocuments::IE::DF do
11
12
  describe "#valid?" do
12
13
  it "is invalid with malformed number" do
13
14
  ["070648022871-3", "07.064.802.287-13", "0AB49871799-12"].each do |number|
14
- ie = BrDocuments::IE::DF.new(number)
15
+ ie = described_class.new(number)
15
16
  expect(ie).to_not be_valid
16
17
  end
17
18
  end
18
19
 
19
20
  it "is invalid with length different to 13" do
20
21
  ["1234567890", "123456789012345"].each do |number|
21
- ie = BrDocuments::IE::DF.new(number)
22
+ ie = described_class.new(number)
22
23
  expect(ie).to_not be_valid
23
24
  end
24
25
  end
25
26
 
26
27
  it "is invalid with invalid check number" do
27
28
  ["0733002219945", "0733002219943"].each do |number|
28
- ie = BrDocuments::IE::DF.new(number)
29
+ ie = described_class.new(number)
29
30
  expect(ie).to_not be_valid
30
31
  end
31
32
  end
32
33
 
33
34
  it "is valid with valid number" do
34
35
  ["0746069399231", "0784748156211"].each do |number|
35
- ie = BrDocuments::IE::DF.new(number)
36
+ ie = described_class.new(number)
36
37
  expect(ie).to be_valid
37
38
  end
38
39
  end
40
+
41
+ include_examples "for to remove all masks", "07847481562-11"
39
42
  end
40
43
  end
data/spec/ie/es_spec.rb CHANGED
@@ -1,13 +1,16 @@
1
1
  require "spec_helper"
2
2
  require_relative "shared_examples_for_pattern1"
3
+ require_relative "shared_examples_for_to_remove_all_masks"
3
4
 
4
5
  describe BrDocuments::IE::ES do
5
6
  describe "#formatted" do
6
7
  it "returns a formatted ie" do
7
- ie = BrDocuments::IE::ES.new("123456789")
8
+ ie = described_class.new("123456789")
8
9
  expect(ie.formatted).to eq "123456789"
9
10
  end
10
11
  end
11
12
 
12
13
  it_behaves_like "a pattern1", "ES"
14
+
15
+ include_examples "for to remove all masks", "12345678-9"
13
16
  end
data/spec/ie/go_spec.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  require "spec_helper"
2
+ require_relative "shared_examples_for_to_remove_all_masks"
2
3
 
3
4
  describe BrDocuments::IE::GO do
4
5
  describe "#formatted" do
5
6
  it "returns a formatted ie" do
6
- ie = BrDocuments::IE::GO.new("123456789")
7
+ ie = described_class.new("123456789")
7
8
  expect(ie.formatted).to eq "12.345.678-9"
8
9
  end
9
10
  end
@@ -11,30 +12,32 @@ describe BrDocuments::IE::GO do
11
12
  describe "#valid?" do
12
13
  it "is invalid with malformed number" do
13
14
  ["01.390415.9", "280541-600", "1C78150A5"].each do |number|
14
- ie = BrDocuments::IE::GO.new(number)
15
+ ie = described_class.new(number)
15
16
  expect(ie).to_not be_valid
16
17
  end
17
18
  end
18
19
 
19
20
  it "is invalid with length different to 9" do
20
21
  ["1234567", "122345678901"].each do |number|
21
- ie = BrDocuments::IE::GO.new(number)
22
+ ie = described_class.new(number)
22
23
  expect(ie).to_not be_valid
23
24
  end
24
25
  end
25
26
 
26
27
  it "is invalid with invalid check number" do
27
28
  ["903473566", "493184742"].each do |number|
28
- ie = BrDocuments::IE::GO.new(number)
29
+ ie = described_class.new(number)
29
30
  expect(ie).to_not be_valid
30
31
  end
31
32
  end
32
33
 
33
34
  it "is valid with valid number" do
34
35
  ["155432214", "916876470"].each do |number|
35
- ie = BrDocuments::IE::GO.new(number)
36
+ ie = described_class.new(number)
36
37
  expect(ie).to be_valid
37
38
  end
38
39
  end
40
+
41
+ include_examples "for to remove all masks", "91.687.647-0"
39
42
  end
40
43
  end
data/spec/ie/ma_spec.rb CHANGED
@@ -1,13 +1,16 @@
1
1
  require "spec_helper"
2
2
  require_relative "shared_examples_for_pattern1"
3
+ require_relative "shared_examples_for_to_remove_all_masks"
3
4
 
4
5
  describe BrDocuments::IE::MA do
5
6
  describe "#formatted" do
6
7
  it "returns a formatted ie" do
7
- ie = BrDocuments::IE::MA.new("123456789")
8
+ ie = described_class.new("123456789")
8
9
  expect(ie.formatted).to eq "123456789"
9
10
  end
10
11
  end
11
12
 
12
13
  it_behaves_like "a pattern1", "MA"
14
+
15
+ include_examples "for to remove all masks", "12345678-9"
13
16
  end
data/spec/ie/mg_spec.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  require "spec_helper"
2
+ require_relative "shared_examples_for_to_remove_all_masks"
2
3
 
3
- describe BrDocuments::IE::MG do
4
+ RSpec.describe BrDocuments::IE::MG do
4
5
  describe "#formatted" do
5
6
  it "returns a formatted ie" do
6
- ie = BrDocuments::IE::MG.new("1234567890123")
7
+ ie = described_class.new("1234567890123")
7
8
  expect(ie.formatted).to eq "123.456.789/0123"
8
9
  end
9
10
  end
@@ -11,30 +12,32 @@ describe BrDocuments::IE::MG do
11
12
  describe "#valid?" do
12
13
  it "is invalid with malformed number" do
13
14
  ["36.311.266.571-75", "4.168.836.973-423", "560.139.778.87-BA"].each do |number|
14
- ie = BrDocuments::IE::MG.new(number)
15
+ ie = described_class.new(number)
15
16
  expect(ie).to_not be_valid
16
17
  end
17
18
  end
18
19
 
19
20
  it "is invalid with length different to 13" do
20
21
  ["123456789", "1234567890123"].each do |number|
21
- ie = BrDocuments::IE::MG.new(number)
22
+ ie = described_class.new(number)
22
23
  expect(ie).to_not be_valid
23
24
  end
24
25
  end
25
26
 
26
27
  it "is invalid with invalid check number" do
27
28
  ["4193434759812", "9427301981832"].each do |number|
28
- ie = BrDocuments::IE::MG.new(number)
29
+ ie = described_class.new(number)
29
30
  expect(ie).to_not be_valid
30
31
  end
31
32
  end
32
33
 
33
34
  it "is valid with valid number" do
34
35
  ["4193434759899", "9427301981820"].each do |number|
35
- ie = BrDocuments::IE::MG.new(number)
36
+ ie = described_class.new(number)
36
37
  expect(ie).to be_valid
37
38
  end
38
39
  end
40
+
41
+ include_examples "for to remove all masks", "942.730.198.18-20"
39
42
  end
40
43
  end
data/spec/ie/ms_spec.rb CHANGED
@@ -1,13 +1,16 @@
1
1
  require "spec_helper"
2
2
  require_relative "shared_examples_for_pattern1"
3
+ require_relative "shared_examples_for_to_remove_all_masks"
3
4
 
4
5
  describe BrDocuments::IE::MS do
5
6
  describe "#formatted" do
6
7
  it "returns a formatted ie" do
7
- ie = BrDocuments::IE::MS.new("123456789")
8
+ ie = described_class.new("123456789")
8
9
  expect(ie.formatted).to eq "123456789"
9
10
  end
10
11
  end
11
12
 
12
13
  it_behaves_like "a pattern1", "MS"
14
+
15
+ include_examples "for to remove all masks", "12345678-9"
13
16
  end