br_documents 0.0.9 → 0.0.10

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: 2868a841f5b9a2487fa3fa00f9c9beb4ff4920ac
4
- data.tar.gz: f0d3e96b7388d21779b704098eec4839943800d0
3
+ metadata.gz: f9bb58e73c2ffeeb543165040e7e6e51e21d8f1e
4
+ data.tar.gz: 79b96cbdc6e69c33a6f6738f7972ab2303d887ea
5
5
  SHA512:
6
- metadata.gz: 42d5062406d40d444454a9df7ebd2f954d12a2e7681f93148cf261d2de1b3dc7f3e308bd3df648a424e4fbe9d43d79db627ea2fd889f8656a7b633ca0620cae9
7
- data.tar.gz: 24711a1be9598e21df60eaa4e0ed27f447d047dffb6b0637c41ebd9734466b587038dd7db215c0e24015765da2e227a6088d3161e3e25830464866981c0148e8
6
+ metadata.gz: 3de3927c7117bc94acbf2edbb6f235bb188e7e1782cb425c0c73c3063d217930a054d84b8708d99bc50bee53ce7242a6b86f65afdc34d9462ec6826934406703
7
+ data.tar.gz: 3ad7723c2eb9c82d0f55009ae2002ca245a77b2acdce8e448377c7491f0fb24aa49f3ccaf921d88f8de4335669213a0e869ea61426ba7c26299c5e042f6aaf66
data/README.md CHANGED
@@ -120,6 +120,8 @@ pj.valid? # => false
120
120
  #### CNPJ
121
121
 
122
122
  ```ruby
123
+ require "br_documents"
124
+
123
125
  cnpj = BrDocuments::CnpjCpf::Cnpj.new("04001155000101")
124
126
  cnpj.formatted # => "04.001.155/0001-01"
125
127
  cnpj.valid? # => true
@@ -128,6 +130,8 @@ cnpj.valid? # => true
128
130
  #### CPF
129
131
 
130
132
  ```ruby
133
+ require "br_documents"
134
+
131
135
  cpf = BrDocuments::CnpjCpf::Cpf.new("11144477735")
132
136
  cpf.formatted # => "111.444.777-35"
133
137
  cpf.valid? # => true
@@ -136,6 +140,8 @@ cpf.valid? # => true
136
140
  #### IE
137
141
 
138
142
  ```ruby
143
+ require "br_documents"
144
+
139
145
  ie = BrDocuments::IE::Factory.create("SC", "254062407")
140
146
  ie.formatted # => "254.062.407"
141
147
  ie.valid? # => true
@@ -4,12 +4,20 @@ module BrDocuments
4
4
  module IE
5
5
  class MT < Pattern1
6
6
  def initialize(number)
7
+ complete_with_zeros(number) { |completted| number = completted }
8
+
7
9
  super
8
- @mask = /^(\d{10}\-\d{1})$|^(\d{11})$/
10
+ @mask = /^\d{4}\.?\d{3}\.?\d{3}\-?\d{1}$/
9
11
  @weight = [3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
10
12
  end
11
13
 
12
14
  private
15
+ def complete_with_zeros(number)
16
+ just_numbers = number.gsub(/[\.\/-]/, "")
17
+ zeros = ("0" * 11).slice(just_numbers.length, 11)
18
+ yield "#{zeros}#{number}" if block_given?
19
+ end
20
+
13
21
  def format_ie(number)
14
22
  number.sub(/(\d{10})(\d{1})/, "\\1-\\2")
15
23
  end
@@ -5,7 +5,7 @@ module BrDocuments
5
5
  class RJ < Pattern1
6
6
  def initialize(number)
7
7
  super
8
- @mask = /^(\d{2}\.\d{3}\.\d{2}\-\d{1})$|^(\d{8})$/
8
+ @mask = /^(\d{2}\.\d{3}\.\d{2}\-?\d{1})$|^(\d{8})$/
9
9
  @weight = [2, 7, 6, 5, 4, 3, 2]
10
10
  end
11
11
 
@@ -1,3 +1,3 @@
1
1
  module BrDocuments
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
data/spec/ie/mt_spec.rb CHANGED
@@ -16,10 +16,11 @@ describe BrDocuments::IE::MT do
16
16
  end
17
17
  end
18
18
 
19
- it "is invalid with length different to 11" do
20
- ["123456789012", "123456789"].each do |number|
21
- ie = BrDocuments::IE::MT.new(number)
22
- expect(ie).to_not be_valid
19
+ context "when the number is greater than 11" do
20
+ subject { BrDocuments::IE::MT.new("123456789012") }
21
+
22
+ it "is invalid " do
23
+ expect(subject).to_not be_valid
23
24
  end
24
25
  end
25
26
 
@@ -31,7 +32,7 @@ describe BrDocuments::IE::MT do
31
32
  end
32
33
 
33
34
  it "is valid with valid number" do
34
- ["00130000019", "82060187373"].each do |number|
35
+ ["0013000001-9", "82060187373", "132631946", "13.263.194-6"].each do |number|
35
36
  ie = BrDocuments::IE::MT.new(number)
36
37
  expect(ie).to be_valid
37
38
  end
data/spec/ie/rj_spec.rb CHANGED
@@ -31,7 +31,7 @@ describe BrDocuments::IE::RJ do
31
31
  end
32
32
 
33
33
  it "is valid with valid number" do
34
- ["80172010", "31864950"].each do |number|
34
+ ["80172010", "31.864.95-0", "85.994.964"].each do |number|
35
35
  ie = BrDocuments::IE::RJ.new(number)
36
36
  expect(ie).to be_valid
37
37
  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.9
4
+ version: 0.0.10
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-03-14 00:00:00.000000000 Z
11
+ date: 2015-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel