br_danfe 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -0
- data/br_danfe.gemspec +5 -5
- data/lib/br_danfe.rb +1 -0
- data/lib/br_danfe/danfe.rb +5 -0
- data/lib/br_danfe/dest.rb +6 -3
- data/lib/br_danfe/emit.rb +4 -2
- data/lib/br_danfe/version.rb +1 -1
- data/spec/features/br_danfe_spec.rb +103 -42
- metadata +20 -29
- data/lib/br_danfe/cnpj.rb +0 -7
- data/lib/br_danfe/cpf.rb +0 -7
- data/lib/br_danfe/ie.rb +0 -20
- data/lib/br_danfe/ie_masks.rb +0 -75
- data/spec/lib/cnpj_spec.rb +0 -10
- data/spec/lib/cpf_spec.rb +0 -10
- data/spec/lib/ie_spec.rb +0 -230
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24eba63681a40040bfa5b2ef632cd029891fe384
|
4
|
+
data.tar.gz: b9ac26036d59bf03232df57c590a82bb2cb404b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 710fd0835151a2b5acb85c1a947eacdbea635211b3845fb3c463a00bf38475b826dbe60217816e6879614dc3589a42771b5c4e0a1d04a176db769669b4cc7938
|
7
|
+
data.tar.gz: b7ed4f47d1b50814dabe29244c0210a133a50e23b8ff05672207868033404f1acdf0f6ccbc3ac62b0717a62d9c9bf411870e356b7ba69f938c2575dd94f6fb0d
|
data/README.md
CHANGED
@@ -12,12 +12,27 @@ This gem requires `ruby >= 1.9.x`.
|
|
12
12
|
|
13
13
|
## Usage
|
14
14
|
|
15
|
+
### Usage in Ruby
|
16
|
+
|
15
17
|
xml = File.read("nfe.xml")
|
16
18
|
|
17
19
|
danfe = BrDanfe::Danfe.new(xml)
|
18
20
|
danfe.options.logo_path = "logo.png"
|
19
21
|
danfe.save_pdf("nfe.pdf")
|
20
22
|
|
23
|
+
### Usage in Rails Controller
|
24
|
+
|
25
|
+
class DanfeController < ApplicationController
|
26
|
+
def new
|
27
|
+
invoice = Invoice.find(params[:id])
|
28
|
+
xml_as_string = invoice.generate_xml # your method that generates the NF-e's xml
|
29
|
+
|
30
|
+
danfe = BrDanfe::Danfe.new(xml_as_string)
|
31
|
+
|
32
|
+
send_data danfe.render_pdf, filename: "danfe.pdf", type: "application/pdf"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
21
36
|
## I18n
|
22
37
|
|
23
38
|
By default, your rails application must be configured to `pt-Br`.
|
data/br_danfe.gemspec
CHANGED
@@ -17,12 +17,12 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.require_paths = ["lib"]
|
18
18
|
|
19
19
|
spec.add_dependency "nokogiri"
|
20
|
-
spec.add_dependency "prawn"
|
21
|
-
spec.add_dependency "barby"
|
20
|
+
spec.add_dependency "prawn", "1.0.0"
|
21
|
+
spec.add_dependency "barby", "0.5.1"
|
22
22
|
spec.add_dependency "i18n"
|
23
|
+
spec.add_dependency "br_documents", ">= 0.0.8"
|
23
24
|
|
24
|
-
spec.add_development_dependency "
|
25
|
-
spec.add_development_dependency "
|
26
|
-
spec.add_development_dependency "simplecov"
|
25
|
+
spec.add_development_dependency "rspec", ">= 3.0.0"
|
26
|
+
spec.add_development_dependency "simplecov", ">= 0.9.0"
|
27
27
|
spec.add_development_dependency "codeclimate-test-reporter"
|
28
28
|
end
|
data/lib/br_danfe.rb
CHANGED
data/lib/br_danfe/danfe.rb
CHANGED
data/lib/br_danfe/dest.rb
CHANGED
@@ -29,11 +29,13 @@ module BrDanfe
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def cnpj
|
32
|
-
Cnpj.
|
32
|
+
cnpj = BrDocuments::CnpjCpf::Cnpj.new(@xml["dest/CNPJ"])
|
33
|
+
cnpj.formatted
|
33
34
|
end
|
34
35
|
|
35
36
|
def cpf
|
36
|
-
Cpf.
|
37
|
+
cpf = BrDocuments::CnpjCpf::Cpf.new(@xml["dest/CPF"])
|
38
|
+
cpf.formatted
|
37
39
|
end
|
38
40
|
|
39
41
|
def render_line2
|
@@ -64,7 +66,8 @@ module BrDanfe
|
|
64
66
|
end
|
65
67
|
|
66
68
|
def ie
|
67
|
-
|
69
|
+
ie = BrDocuments::IE::Factory.create(@xml["enderDest/UF"], @xml["dest/IE"])
|
70
|
+
ie.formatted
|
68
71
|
end
|
69
72
|
end
|
70
73
|
end
|
data/lib/br_danfe/emit.rb
CHANGED
@@ -99,11 +99,13 @@ module BrDanfe
|
|
99
99
|
end
|
100
100
|
|
101
101
|
def ie(x, field)
|
102
|
-
|
102
|
+
ie = BrDocuments::IE::Factory.create(@xml["enderEmit/UF"], @xml["emit/#{field}"])
|
103
|
+
@pdf.ibox 0.85, 6.86, x, 7.31, I18n.t("danfe.emit.#{field}"), ie.formatted
|
103
104
|
end
|
104
105
|
|
105
106
|
def cnpj_box
|
106
|
-
|
107
|
+
cnpj = BrDocuments::CnpjCpf::Cnpj.new(@xml["emit/CNPJ"])
|
108
|
+
@pdf.ibox 0.85, 6.84, 13.97, 7.31, I18n.t("danfe.emit.CNPJ"), cnpj.formatted
|
107
109
|
end
|
108
110
|
end
|
109
111
|
end
|
data/lib/br_danfe/version.rb
CHANGED
@@ -4,69 +4,130 @@ describe "BrDanfe generated pdf files" do
|
|
4
4
|
let(:base_dir) { "./spec/fixtures/"}
|
5
5
|
let(:output_pdf) { "#{base_dir}output.pdf" }
|
6
6
|
|
7
|
-
|
7
|
+
describe "#render_pdf" do
|
8
|
+
it "renders a basic NF-e with namespace" do
|
9
|
+
danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_with_ns.xml"))
|
8
10
|
|
9
|
-
|
10
|
-
expect(File.exist?(output_pdf)).to be_false
|
11
|
+
expected = IO.binread("#{base_dir}nfe_with_ns.xml.fixture.pdf")
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
expect(danfe.render_pdf).to eq expected
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
it "renders another basic NF-e without namespace" do
|
17
|
+
danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_without_ns.xml"))
|
17
18
|
|
18
|
-
|
19
|
-
expect(File.exist?(output_pdf)).to be_false
|
19
|
+
expected = IO.binread("#{base_dir}nfe_without_ns.xml.fixture.pdf")
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
expect(danfe.render_pdf).to eq expected
|
22
|
+
end
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
it "renders a NF-e having FCI in its items" do
|
25
|
+
danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_with_fci.xml"))
|
26
26
|
|
27
|
-
|
28
|
-
expect(File.exist?(output_pdf)).to be_false
|
27
|
+
expected = IO.binread("#{base_dir}nfe_with_fci.xml.fixture.pdf")
|
29
28
|
|
30
|
-
|
31
|
-
|
29
|
+
expect(danfe.render_pdf).to eq expected
|
30
|
+
end
|
32
31
|
|
33
|
-
|
34
|
-
|
32
|
+
it "renders a Simples Nacional NF-e using CSOSN" do
|
33
|
+
danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_simples_nacional.xml"))
|
35
34
|
|
36
|
-
|
37
|
-
expect(File.exist?(output_pdf)).to be_false
|
35
|
+
expected = IO.binread("#{base_dir}nfe_simples_nacional.xml.fixture.pdf")
|
38
36
|
|
39
|
-
|
40
|
-
|
37
|
+
expect(danfe.render_pdf).to eq expected
|
38
|
+
end
|
41
39
|
|
42
|
-
|
43
|
-
|
40
|
+
it "renders a NF-e with extra volumes" do
|
41
|
+
danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_with_extra_volumes.xml"))
|
44
42
|
|
45
|
-
|
46
|
-
expect(File.exist?(output_pdf)).to be_false
|
43
|
+
expected = IO.binread("#{base_dir}nfe_with_extra_volumes.xml.fixture.pdf")
|
47
44
|
|
48
|
-
|
49
|
-
|
45
|
+
expect(danfe.render_pdf).to eq expected
|
46
|
+
end
|
50
47
|
|
51
|
-
|
52
|
-
|
48
|
+
it "renders a NF-e with logo" do
|
49
|
+
danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_with_logo.xml"))
|
50
|
+
danfe.options.logo_path = "./spec/fixtures/nfe_with_logo.xml.logo.png"
|
51
|
+
|
52
|
+
expected = IO.binread("#{base_dir}nfe_with_logo.xml.fixture.pdf")
|
53
|
+
|
54
|
+
expect(danfe.render_pdf).to eq expected
|
55
|
+
end
|
53
56
|
|
54
|
-
|
55
|
-
|
57
|
+
it "renders a NF-e with CPF" do
|
58
|
+
danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_with_cpf.xml"))
|
56
59
|
|
57
|
-
|
58
|
-
danfe.options.logo_path = "./spec/fixtures/nfe_with_logo.xml.logo.png"
|
59
|
-
danfe.save_pdf output_pdf
|
60
|
+
expected = IO.binread("#{base_dir}nfe_with_cpf.xml.fixture.pdf")
|
60
61
|
|
61
|
-
|
62
|
+
expect(danfe.render_pdf).to eq expected
|
63
|
+
end
|
62
64
|
end
|
63
65
|
|
64
|
-
|
65
|
-
|
66
|
+
describe "#save_pdf" do
|
67
|
+
before { File.delete(output_pdf) if File.exist?(output_pdf) }
|
68
|
+
|
69
|
+
it "renders a basic NF-e with namespace" do
|
70
|
+
expect(File.exist?(output_pdf)).to be_falsey
|
71
|
+
|
72
|
+
danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_with_ns.xml"))
|
73
|
+
danfe.save_pdf output_pdf
|
74
|
+
|
75
|
+
expect("#{base_dir}nfe_with_ns.xml.fixture.pdf").to be_same_file_as(output_pdf)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "renders another basic NF-e without namespace" do
|
79
|
+
expect(File.exist?(output_pdf)).to be_falsey
|
80
|
+
|
81
|
+
danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_without_ns.xml"))
|
82
|
+
danfe.save_pdf output_pdf
|
83
|
+
|
84
|
+
expect("#{base_dir}nfe_without_ns.xml.fixture.pdf").to be_same_file_as(output_pdf)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "renders a NF-e having FCI in its items" do
|
88
|
+
expect(File.exist?(output_pdf)).to be_falsey
|
89
|
+
|
90
|
+
danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_with_fci.xml"))
|
91
|
+
danfe.save_pdf output_pdf
|
92
|
+
|
93
|
+
expect("#{base_dir}nfe_with_fci.xml.fixture.pdf").to be_same_file_as(output_pdf)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "renders a Simples Nacional NF-e using CSOSN" do
|
97
|
+
expect(File.exist?(output_pdf)).to be_falsey
|
98
|
+
|
99
|
+
danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_simples_nacional.xml"))
|
100
|
+
danfe.save_pdf output_pdf
|
101
|
+
|
102
|
+
expect("#{base_dir}nfe_simples_nacional.xml.fixture.pdf").to be_same_file_as(output_pdf)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "renders a NF-e with extra volumes" do
|
106
|
+
expect(File.exist?(output_pdf)).to be_falsey
|
107
|
+
|
108
|
+
danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_with_extra_volumes.xml"))
|
109
|
+
danfe.save_pdf output_pdf
|
110
|
+
|
111
|
+
expect("#{base_dir}nfe_with_extra_volumes.xml.fixture.pdf").to be_same_file_as(output_pdf)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "renders a NF-e with logo" do
|
115
|
+
expect(File.exist?(output_pdf)).to be_falsey
|
116
|
+
|
117
|
+
danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_with_logo.xml"))
|
118
|
+
danfe.options.logo_path = "./spec/fixtures/nfe_with_logo.xml.logo.png"
|
119
|
+
danfe.save_pdf output_pdf
|
120
|
+
|
121
|
+
expect("#{base_dir}nfe_with_logo.xml.fixture.pdf").to be_same_file_as(output_pdf)
|
122
|
+
end
|
123
|
+
|
124
|
+
it "renders a NF-e with CPF" do
|
125
|
+
expect(File.exist?(output_pdf)).to be_falsey
|
66
126
|
|
67
|
-
|
68
|
-
|
127
|
+
danfe = BrDanfe::Danfe.new(File.read("#{base_dir}nfe_with_cpf.xml"))
|
128
|
+
danfe.save_pdf output_pdf
|
69
129
|
|
70
|
-
|
130
|
+
expect("#{base_dir}nfe_with_cpf.xml.fixture.pdf").to be_same_file_as(output_pdf)
|
131
|
+
end
|
71
132
|
end
|
72
133
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: br_danfe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ASSEINFO
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -28,30 +28,30 @@ dependencies:
|
|
28
28
|
name: prawn
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - '
|
31
|
+
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 1.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - '
|
38
|
+
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 1.0.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: barby
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - '
|
45
|
+
- - '='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 0.5.1
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - '
|
52
|
+
- - '='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 0.5.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: i18n
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,47 +67,47 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: br_documents
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
76
|
-
type: :
|
75
|
+
version: 0.0.8
|
76
|
+
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 0.0.8
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - '>='
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 3.0.0
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 3.0.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: simplecov
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - '>='
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
103
|
+
version: 0.9.0
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - '>='
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
110
|
+
version: 0.9.0
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: codeclimate-test-reporter
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -138,8 +138,6 @@ files:
|
|
138
138
|
- config/locales/pt-BR.yml
|
139
139
|
- lib/br_danfe.rb
|
140
140
|
- lib/br_danfe/cep.rb
|
141
|
-
- lib/br_danfe/cnpj.rb
|
142
|
-
- lib/br_danfe/cpf.rb
|
143
141
|
- lib/br_danfe/cst.rb
|
144
142
|
- lib/br_danfe/danfe.rb
|
145
143
|
- lib/br_danfe/dest.rb
|
@@ -150,8 +148,6 @@ files:
|
|
150
148
|
- lib/br_danfe/emit.rb
|
151
149
|
- lib/br_danfe/helper.rb
|
152
150
|
- lib/br_danfe/icmstot.rb
|
153
|
-
- lib/br_danfe/ie.rb
|
154
|
-
- lib/br_danfe/ie_masks.rb
|
155
151
|
- lib/br_danfe/infadic.rb
|
156
152
|
- lib/br_danfe/issqn.rb
|
157
153
|
- lib/br_danfe/options.rb
|
@@ -180,11 +176,8 @@ files:
|
|
180
176
|
- spec/fixtures/nfe_without_ns.xml
|
181
177
|
- spec/fixtures/nfe_without_ns.xml.fixture.pdf
|
182
178
|
- spec/lib/cep_spec.rb
|
183
|
-
- spec/lib/cnpj_spec.rb
|
184
|
-
- spec/lib/cpf_spec.rb
|
185
179
|
- spec/lib/cst_spec.rb
|
186
180
|
- spec/lib/helper_spec.rb
|
187
|
-
- spec/lib/ie_spec.rb
|
188
181
|
- spec/lib/options_spec.rb
|
189
182
|
- spec/lib/phone_spec.rb
|
190
183
|
- spec/lib/plate_spec.rb
|
@@ -211,7 +204,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
211
204
|
version: '0'
|
212
205
|
requirements: []
|
213
206
|
rubyforge_project:
|
214
|
-
rubygems_version: 2.
|
207
|
+
rubygems_version: 2.2.2
|
215
208
|
signing_key:
|
216
209
|
specification_version: 4
|
217
210
|
summary: DANFE pdf generator for Brazilian invoices.
|
@@ -233,14 +226,12 @@ test_files:
|
|
233
226
|
- spec/fixtures/nfe_without_ns.xml
|
234
227
|
- spec/fixtures/nfe_without_ns.xml.fixture.pdf
|
235
228
|
- spec/lib/cep_spec.rb
|
236
|
-
- spec/lib/cnpj_spec.rb
|
237
|
-
- spec/lib/cpf_spec.rb
|
238
229
|
- spec/lib/cst_spec.rb
|
239
230
|
- spec/lib/helper_spec.rb
|
240
|
-
- spec/lib/ie_spec.rb
|
241
231
|
- spec/lib/options_spec.rb
|
242
232
|
- spec/lib/phone_spec.rb
|
243
233
|
- spec/lib/plate_spec.rb
|
244
234
|
- spec/lib/xprod_spec.rb
|
245
235
|
- spec/spec_helper.rb
|
246
236
|
- spec/support/be_same_file_as.rb
|
237
|
+
has_rdoc:
|
data/lib/br_danfe/cnpj.rb
DELETED
data/lib/br_danfe/cpf.rb
DELETED
data/lib/br_danfe/ie.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
module BrDanfe
|
2
|
-
class Ie
|
3
|
-
def self.format(ie, uf)
|
4
|
-
uf = uf.upcase
|
5
|
-
|
6
|
-
if ["AL", "AP", "MA", "ES", "MS", "PI", "TO"].include?(uf)
|
7
|
-
formatted = ie
|
8
|
-
elsif ["CE", "PB", "RR", "SE"].include?(uf)
|
9
|
-
formatted = ie.sub(/(\d{8})(\d{1})/, "\\1-\\2")
|
10
|
-
elsif ["AM", "GO"].include?(uf)
|
11
|
-
formatted = ie.sub(/(\d{2})(\d{3})(\d{3})(\d{1})/, "\\1.\\2.\\3-\\4")
|
12
|
-
else
|
13
|
-
masks = IeMasks.new
|
14
|
-
formatted = masks.send("apply_mask_for_#{uf.downcase}", ie)
|
15
|
-
end
|
16
|
-
|
17
|
-
formatted
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
data/lib/br_danfe/ie_masks.rb
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
module BrDanfe
|
2
|
-
class IeMasks
|
3
|
-
def apply_mask_for_sp(ie)
|
4
|
-
if ie.length == 12
|
5
|
-
ie.sub(/(\d{3})(\d{3})(\d{3})(\d{3})/, "\\1.\\2.\\3.\\4")
|
6
|
-
else
|
7
|
-
ie.sub(/(\w{1})(\d{8})(\d{1})(\d{3})/, "\\1-\\2.\\3/\\4")
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def apply_mask_for_ba(ie)
|
12
|
-
if ie.length == 8
|
13
|
-
ie.sub(/(\d{6})(\d{2})/, "\\1-\\2")
|
14
|
-
else
|
15
|
-
ie.sub(/(\d{7})(\d{2})/, "\\1-\\2")
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def apply_mask_for_ro(ie)
|
20
|
-
if ie.length == 9
|
21
|
-
ie.sub(/(\d{3})(\d{5})(\d{1})/, "\\1.\\2-\\3")
|
22
|
-
else
|
23
|
-
ie.sub(/(\d{13})(\d{1})/, "\\1-\\2")
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def apply_mask_for_rn(ie)
|
28
|
-
if ie.length == 9
|
29
|
-
ie.sub(/(\d{2})(\d{3})(\d{3})(\d{1})/, "\\1.\\2.\\3-\\4")
|
30
|
-
else
|
31
|
-
ie.sub(/(\d{2})(\d{1})(\d{3})(\d{3})(\d{1})/, "\\1.\\2.\\3.\\4-\\5")
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def apply_mask_for_ac(ie)
|
36
|
-
ie.sub(/(\d{2})(\d{3})(\d{3})(\d{3})(\d{2})/, "\\1.\\2.\\3/\\4-\\5")
|
37
|
-
end
|
38
|
-
|
39
|
-
def apply_mask_for_df(ie)
|
40
|
-
ie.sub(/(\d{11})(\d{2})/, "\\1-\\2")
|
41
|
-
end
|
42
|
-
|
43
|
-
def apply_mask_for_mg(ie)
|
44
|
-
ie.sub(/(\d{3})(\d{3})(\d{3})(\d{4})/, "\\1.\\2.\\3/\\4")
|
45
|
-
end
|
46
|
-
|
47
|
-
def apply_mask_for_mt(ie)
|
48
|
-
ie.sub(/(\d{10})(\d{1})/, "\\1-\\2")
|
49
|
-
end
|
50
|
-
|
51
|
-
def apply_mask_for_rj(ie)
|
52
|
-
ie.sub(/(\d{2})(\d{3})(\d{2})(\d{1})/, "\\1.\\2.\\3-\\4")
|
53
|
-
end
|
54
|
-
|
55
|
-
def apply_mask_for_pr(ie)
|
56
|
-
ie.sub(/(\d{8})(\d{2})/, "\\1-\\2")
|
57
|
-
end
|
58
|
-
|
59
|
-
def apply_mask_for_rs(ie)
|
60
|
-
ie.sub(/(\d{3})(\d{7})/, "\\1/\\2")
|
61
|
-
end
|
62
|
-
|
63
|
-
def apply_mask_for_pe(ie)
|
64
|
-
ie.sub(/(\d{7})(\d{2})/, "\\1-\\2")
|
65
|
-
end
|
66
|
-
|
67
|
-
def apply_mask_for_pa(ie)
|
68
|
-
ie.sub(/(\d{2})(\d{6})(\d{1})/, "\\1-\\2-\\3")
|
69
|
-
end
|
70
|
-
|
71
|
-
def apply_mask_for_sc(ie)
|
72
|
-
ie.sub(/(\d{3})(\d{3})(\d{3})/, "\\1.\\2.\\3")
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
data/spec/lib/cnpj_spec.rb
DELETED
data/spec/lib/cpf_spec.rb
DELETED
data/spec/lib/ie_spec.rb
DELETED
@@ -1,230 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe BrDanfe::Ie do
|
4
|
-
describe ".format" do
|
5
|
-
context "when UF is AC" do
|
6
|
-
it "returns a formated ie" do
|
7
|
-
ie = "1234567890123"
|
8
|
-
expect(BrDanfe::Ie.format(ie, "AC")).to eq "12.345.678/901-23"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
context "when UF is AL" do
|
13
|
-
it "returns a formated ie" do
|
14
|
-
ie = "123456789"
|
15
|
-
expect(BrDanfe::Ie.format(ie, "AL")).to eq "123456789"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
context "when UF is AP" do
|
20
|
-
it "returns a formated ie" do
|
21
|
-
ie = "123456789"
|
22
|
-
expect(BrDanfe::Ie.format(ie, "AP")).to eq "123456789"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context "when UF is AM" do
|
27
|
-
it "returns a formated ie" do
|
28
|
-
ie = "123456789"
|
29
|
-
expect(BrDanfe::Ie.format(ie, "AM")).to eq "12.345.678-9"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context "when UF is BA" do
|
34
|
-
context "when IE have 8 digits" do
|
35
|
-
it "returns a formated ie" do
|
36
|
-
ie = "12345678"
|
37
|
-
expect(BrDanfe::Ie.format(ie, "BA")).to eq "123456-78"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context "when IE have 9 digits" do
|
42
|
-
it "returns a formated ie" do
|
43
|
-
ie = "123456789"
|
44
|
-
expect(BrDanfe::Ie.format(ie, "BA")).to eq "1234567-89"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context "when UF is CE" do
|
50
|
-
it "returns a formated ie" do
|
51
|
-
ie = "123456789"
|
52
|
-
expect(BrDanfe::Ie.format(ie, "CE")).to eq "12345678-9"
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context "when UF is DF" do
|
57
|
-
it "returns a formated ie" do
|
58
|
-
ie = "1234567890123"
|
59
|
-
expect(BrDanfe::Ie.format(ie, "DF")).to eq "12345678901-23"
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context "when UF is ES" do
|
64
|
-
it "returns a formated ie" do
|
65
|
-
ie = "123456789"
|
66
|
-
expect(BrDanfe::Ie.format(ie, "ES")).to eq "123456789"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
context "when UF is GO" do
|
71
|
-
it "returns a formated ie" do
|
72
|
-
ie = "123456789"
|
73
|
-
expect(BrDanfe::Ie.format(ie, "GO")).to eq "12.345.678-9"
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context "when UF is MA" do
|
78
|
-
it "returns a formated ie" do
|
79
|
-
ie = "123456789"
|
80
|
-
expect(BrDanfe::Ie.format(ie, "MA")).to eq "123456789"
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
context "when UF is MT" do
|
85
|
-
it "returns a formated ie" do
|
86
|
-
ie = "12345678901"
|
87
|
-
expect(BrDanfe::Ie.format(ie, "MT")).to eq "1234567890-1"
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
context "when UF is MS" do
|
92
|
-
it "returns a formated ie" do
|
93
|
-
ie = "12345678"
|
94
|
-
expect(BrDanfe::Ie.format(ie, "MS")).to eq "12345678"
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
context "when UF is MG" do
|
99
|
-
it "returns a formated ie" do
|
100
|
-
ie = "1234567890123"
|
101
|
-
expect(BrDanfe::Ie.format(ie, "MG")).to eq "123.456.789/0123"
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
context "when UF is PA" do
|
106
|
-
it "returns a formated ie" do
|
107
|
-
ie = "123456789"
|
108
|
-
expect(BrDanfe::Ie.format(ie, "PA")).to eq "12-345678-9"
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
context "when UF is PB" do
|
113
|
-
it "returns a formated ie" do
|
114
|
-
ie = "123456789"
|
115
|
-
expect(BrDanfe::Ie.format(ie, "PB")).to eq "12345678-9"
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
context "when UF is PR" do
|
120
|
-
it "returns a formated ie" do
|
121
|
-
ie = "1234567890"
|
122
|
-
expect(BrDanfe::Ie.format(ie, "PR")).to eq "12345678-90"
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
context "when UF is PE" do
|
127
|
-
it "returns a formated ie" do
|
128
|
-
ie = "123456789"
|
129
|
-
expect(BrDanfe::Ie.format(ie, "PE")).to eq "1234567-89"
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
context "when UF is PI" do
|
134
|
-
it "returns a formated ie" do
|
135
|
-
ie = "123456789"
|
136
|
-
expect(BrDanfe::Ie.format(ie, "PI")).to eq "123456789"
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
context "when UF is RJ" do
|
141
|
-
it "returns a formated ie" do
|
142
|
-
ie = "12345678"
|
143
|
-
expect(BrDanfe::Ie.format(ie, "RJ")).to eq "12.345.67-8"
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
context "when UF is RN" do
|
148
|
-
context "when IE have 9 digits" do
|
149
|
-
it "returns a formated ie" do
|
150
|
-
ie = "123456789"
|
151
|
-
expect(BrDanfe::Ie.format(ie, "RN")).to eq "12.345.678-9"
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
context "when IE have 10 digits" do
|
156
|
-
it "eturns a formated ie" do
|
157
|
-
ie = "1234567890"
|
158
|
-
expect(BrDanfe::Ie.format(ie, "RN")).to eq "12.3.456.789-0"
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
context "when UF is RS" do
|
164
|
-
it "returns a formated ie" do
|
165
|
-
ie = "1234567890"
|
166
|
-
expect(BrDanfe::Ie.format(ie, "RS")).to eq "123/4567890"
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
context "when UF is RO" do
|
171
|
-
context "when IE have 9 digits" do
|
172
|
-
it "returns a formated ie" do
|
173
|
-
ie = "123456789"
|
174
|
-
expect(BrDanfe::Ie.format(ie, "RO")).to eq "123.45678-9"
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
context "when IE have 14 digits" do
|
179
|
-
it "returns a formated ie" do
|
180
|
-
ie = "12345678901234"
|
181
|
-
expect(BrDanfe::Ie.format(ie, "RO")).to eq "1234567890123-4"
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
context "when UF is RR" do
|
187
|
-
it "returns a formated ie" do
|
188
|
-
ie = "123456789"
|
189
|
-
expect(BrDanfe::Ie.format(ie, "RR")).to eq "12345678-9"
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
context "when UF is SC" do
|
194
|
-
it "returns a formated ie" do
|
195
|
-
ie = "123456789"
|
196
|
-
expect(BrDanfe::Ie.format(ie, "SC")).to eq "123.456.789"
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
context "when UF is SP" do
|
201
|
-
context "when IE have 12 digits" do
|
202
|
-
it "returns a formated ie" do
|
203
|
-
ie = "123456789012"
|
204
|
-
expect(BrDanfe::Ie.format(ie, "SP")).to eq "123.456.789.012"
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
context "when IE have 13 digits" do
|
209
|
-
it "returns a formated ie" do
|
210
|
-
ie = "A123456789012"
|
211
|
-
expect(BrDanfe::Ie.format(ie, "SP")).to eq "A-12345678.9/012"
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
context "when UF is SE" do
|
217
|
-
it "returns a formated ie" do
|
218
|
-
ie = "123456789"
|
219
|
-
expect(BrDanfe::Ie.format(ie, "SE")).to eq "12345678-9"
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
context "when UF is TO" do
|
224
|
-
it "returns a formated ie" do
|
225
|
-
ie = "12345678901"
|
226
|
-
expect(BrDanfe::Ie.format(ie, "TO")).to eq "12345678901"
|
227
|
-
end
|
228
|
-
end
|
229
|
-
end
|
230
|
-
end
|