br_danfe 1.2.3 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/config.yml +5 -7
  3. data/Gemfile +15 -0
  4. data/Gemfile.lock +45 -27
  5. data/br_danfe.gemspec +1 -12
  6. data/config/locales/pt-BR.yml +4 -3
  7. data/lib/br_danfe/cce_lib/document.rb +2 -2
  8. data/lib/br_danfe/danfe_lib/nfce_lib/document.rb +2 -2
  9. data/lib/br_danfe/danfe_lib/nfce_lib/header.rb +1 -1
  10. data/lib/br_danfe/danfe_lib/nfe_lib/dest.rb +2 -10
  11. data/lib/br_danfe/danfe_lib/nfe_lib/document.rb +9 -9
  12. data/lib/br_danfe/danfe_lib/nfe_lib/emit_header.rb +9 -1
  13. data/lib/br_danfe/danfe_lib/nfe_lib/entrega.rb +2 -10
  14. data/lib/br_danfe/danfe_lib/nfe_lib/infadic.rb +1 -1
  15. data/lib/br_danfe/danfe_lib/nfe_lib/transp.rb +1 -1
  16. data/lib/br_danfe/document_builder.rb +2 -2
  17. data/lib/br_danfe/logo_options.rb +1 -1
  18. data/lib/br_danfe/mdfe_lib/document.rb +2 -2
  19. data/lib/br_danfe/version.rb +1 -1
  20. data/lib/br_danfe.rb +1 -1
  21. data/lib/prawn/font.rb +1 -1
  22. data/spec/br_danfe/cce_lib/barcode_spec.rb +1 -1
  23. data/spec/br_danfe/cce_lib/correction_spec.rb +1 -1
  24. data/spec/br_danfe/cce_lib/document_spec.rb +7 -7
  25. data/spec/br_danfe/cce_lib/footer_spec.rb +1 -1
  26. data/spec/br_danfe/cce_lib/header_spec.rb +1 -1
  27. data/spec/br_danfe/cce_lib/nfe_key_spec.rb +1 -1
  28. data/spec/br_danfe/cce_lib/protocol_spec.rb +1 -1
  29. data/spec/br_danfe/cce_spec.rb +2 -2
  30. data/spec/br_danfe/danfe_lib/nfce_lib/document_spec.rb +1 -1
  31. data/spec/br_danfe/danfe_lib/nfce_lib/footer_spec.rb +1 -1
  32. data/spec/br_danfe/danfe_lib/nfce_lib/header_spec.rb +2 -2
  33. data/spec/br_danfe/danfe_lib/nfce_lib/key_spec.rb +1 -1
  34. data/spec/br_danfe/danfe_lib/nfce_lib/nfce_identification_spec.rb +1 -1
  35. data/spec/br_danfe/danfe_lib/nfce_lib/product_list_spec.rb +1 -1
  36. data/spec/br_danfe/danfe_lib/nfce_lib/recipient_spec.rb +1 -1
  37. data/spec/br_danfe/danfe_lib/nfce_lib/total_list_spec.rb +1 -1
  38. data/spec/br_danfe/danfe_lib/nfce_spec.rb +3 -3
  39. data/spec/br_danfe/danfe_lib/nfe_lib/dest_spec.rb +1 -1
  40. data/spec/br_danfe/danfe_lib/nfe_lib/det_body_spec.rb +8 -8
  41. data/spec/br_danfe/danfe_lib/nfe_lib/document_spec.rb +9 -9
  42. data/spec/br_danfe/danfe_lib/nfe_lib/dup_spec.rb +1 -1
  43. data/spec/br_danfe/danfe_lib/nfe_lib/emit_header_spec.rb +66 -3
  44. data/spec/br_danfe/danfe_lib/nfe_lib/entrega_spec.rb +1 -1
  45. data/spec/br_danfe/danfe_lib/nfe_lib/icmstot_spec.rb +1 -1
  46. data/spec/br_danfe/danfe_lib/nfe_lib/infadic_spec.rb +1 -1
  47. data/spec/br_danfe/danfe_lib/nfe_lib/infadic_vol_spec.rb +1 -1
  48. data/spec/br_danfe/danfe_lib/nfe_lib/issqn_spec.rb +1 -1
  49. data/spec/br_danfe/danfe_lib/nfe_lib/ticket_spec.rb +3 -3
  50. data/spec/br_danfe/danfe_lib/nfe_lib/transp_spec.rb +1 -1
  51. data/spec/br_danfe/danfe_lib/nfe_lib/vol_spec.rb +1 -1
  52. data/spec/br_danfe/danfe_lib/nfe_spec.rb +6 -6
  53. data/spec/br_danfe/mdfe_lib/fisco_control_spec.rb +1 -1
  54. data/spec/br_danfe/mdfe_lib/header_spec.rb +1 -1
  55. data/spec/br_danfe/mdfe_lib/notes_spec.rb +1 -1
  56. data/spec/br_danfe/mdfe_spec.rb +2 -2
  57. data/spec/br_danfe/qr_code_spec.rb +1 -1
  58. data/spec/fixtures/nfe/lib/emit_header#render-nfe_key.pdf +16 -16
  59. data/spec/fixtures/nfe/lib/emit_header#render-second_page.pdf +16 -16
  60. data/spec/fixtures/nfe/lib/emit_header#render-with_cpf.pdf +1075 -2
  61. data/spec/fixtures/nfe/lib/emit_header#render-with_logo.pdf +16 -16
  62. data/spec/fixtures/nfe/lib/emit_header#render-without_logo.pdf +14 -14
  63. data/spec/fixtures/nfe/lib/entrega#render-v2.00.pdf +0 -0
  64. data/spec/fixtures/nfe/lib/entrega#render-with-address-bigger.pdf +0 -0
  65. data/spec/fixtures/nfe/lib/entrega#render-with_cpf.pdf +0 -0
  66. data/spec/fixtures/nfe/v2.00/custom_options.fixture.pdf +17 -17
  67. data/spec/fixtures/nfe/v2.00/nfe_simples_nacional.xml.fixture.pdf +15 -15
  68. data/spec/fixtures/nfe/v2.00/nfe_with_entrega.xml.fixture.pdf +16 -16
  69. data/spec/fixtures/nfe/v2.00/nfe_with_extra_volumes.xml.fixture.pdf +24 -24
  70. data/spec/fixtures/nfe/v2.00/nfe_with_fci.xml.fixture.pdf +15 -15
  71. data/spec/fixtures/nfe/v2.00/nfe_with_ns.xml.fixture.pdf +19 -19
  72. data/spec/fixtures/nfe/v2.00/nfe_without_ns.xml.fixture.pdf +15 -15
  73. data/spec/fixtures/nfe/v3.10/multiples.xmls.on.the.same.pdf.pdf +19 -19
  74. data/spec/fixtures/nfe/v3.10/nfe_simples_nacional.xml.fixture.pdf +15 -15
  75. data/spec/fixtures/nfe/v3.10/with_footer.fixture.pdf +19 -19
  76. data/spec/fixtures/nfe/v3.10/with_issqn.fixture.pdf +15 -15
  77. data/spec/fixtures/nfe/v3.10/with_three_pages.fixture.pdf +23 -23
  78. data/spec/fixtures/nfe/v3.10/without_issqn.fixture.pdf +19 -19
  79. data/spec/spec_helper.rb +9 -1
  80. metadata +8 -160
  81. /data/spec/fixtures/nfe/lib/{document#lcnpj-blank.pdf → document#lcnpj_cpf-blank.pdf} +0 -0
  82. /data/spec/fixtures/nfe/lib/{document#lcnpj-invalid.pdf → document#lcnpj_cpf-invalid.pdf} +0 -0
  83. /data/spec/fixtures/nfe/lib/{document#lcnpj-valid.pdf → document#lcnpj_cpf-valid.pdf} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77b80a670ecd1d7c56bd346ad493a91e28d9b9f58aeff96e2feff598c56ac06d
4
- data.tar.gz: a7fc99c996a113d9a0cade611c1f965ec0854313294004a026b772483b2cc765
3
+ metadata.gz: 262bed0c378422071afeb0a12ce50e4c4f4a5633266dd7893f2d0c280316a55e
4
+ data.tar.gz: 412bdf1269d5d8c542d1ce5504e3b219621215da71019c3e37b0441ddb06d28f
5
5
  SHA512:
6
- metadata.gz: 2d07ec3c1a879cf644791ed3eda0212e9e50dc25259deb5d52172f71f19f48a69955588034d4f36ca165e3ccbf58202e530a4fb8d311494c62907dc2c28e5211
7
- data.tar.gz: 1333a3e830b1d8f3cd53d21dc7d9612153182fb381930a9bd9a773ea1e27c47a25e2d1da07a1da3dc3808ad74960a39436cdc16e32d27fd9e1d24561263bf4b0
6
+ metadata.gz: 811c26b219e61e7a125e9c212ee3750c3ab6016ae6937456397acafd9dce1a03da762f2f50b645b8784ed6c6f8334159933f9aae7b681857e9b439816936cc51
7
+ data.tar.gz: f396a32db9d675a68b87d62aa12d412e73930251c6278d3361cd34db6b7ba7a76048f4c8250335663dca19bac263dddde56f1a6a7506855469a8b715d09daa13
@@ -7,7 +7,7 @@ jobs:
7
7
  strategy:
8
8
  fail-fast: false # I understand this is to run on all versions.
9
9
  matrix:
10
- ruby: ['3.0.4']
10
+ ruby: ['3.3.5']
11
11
 
12
12
  runs-on: ubuntu-latest
13
13
 
@@ -25,7 +25,7 @@ jobs:
25
25
  strategy:
26
26
  fail-fast: false # I understand this is to run on all versions.
27
27
  matrix:
28
- ruby: ['3.0.4']
28
+ ruby: ['3.3.5']
29
29
 
30
30
  runs-on: ubuntu-latest
31
31
 
@@ -38,12 +38,10 @@ jobs:
38
38
  bundler-cache: true
39
39
 
40
40
  - run: |
41
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
42
- chmod +x ./cc-test-reporter
41
+ curl https://qlty.sh | sh
43
42
 
44
43
  - run: |
45
- ./cc-test-reporter before-build
46
44
  bundle exec rspec
47
- ./cc-test-reporter after-build -r $CC_TEST_REPORTER_ID --exit-code $?
45
+ ~/.qlty/bin/qlty coverage publish coverage/coverage.json
48
46
  env:
49
- CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}}
47
+ QLTY_COVERAGE_TOKEN: ${{secrets.QLTY_COVERAGE_TOKEN}}
data/Gemfile CHANGED
@@ -1,3 +1,18 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+ group :development, :test do
6
+ gem 'byebug', '11.1.3'
7
+ gem 'guard', '~> 2.19.0'
8
+ gem 'guard-rspec', '~> 4.7.3'
9
+ gem 'pdf-inspector', '~> 1.3.0'
10
+ gem 'rake', '13.2.1'
11
+ gem 'rspec', '3.13.0'
12
+ gem 'rubocop', '~> 1.75.3'
13
+ gem 'rubocop-performance', '~> 1.19.0'
14
+ gem 'rubocop-rspec', '~> 2.25.0'
15
+ gem 'simplecov', '0.22.0'
16
+ gem 'simplecov-html', '0.13.1'
17
+ gem 'simplecov-json', '0.2.3'
18
+ end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- br_danfe (1.2.3)
4
+ br_danfe (2.1.0)
5
5
  barby (= 0.6.9)
6
6
  br_documents (>= 0.1.3)
7
7
  i18n (>= 0.8.6)
@@ -27,7 +27,7 @@ GEM
27
27
  mutex_m
28
28
  tzinfo (~> 2.0)
29
29
  afm (0.2.2)
30
- ast (2.4.2)
30
+ ast (2.4.3)
31
31
  barby (0.6.9)
32
32
  base64 (0.2.0)
33
33
  bigdecimal (3.1.6)
@@ -62,6 +62,9 @@ GEM
62
62
  hashery (2.1.2)
63
63
  i18n (1.14.5)
64
64
  concurrent-ruby (~> 1.0)
65
+ json (2.11.3)
66
+ language_server-protocol (3.17.0.4)
67
+ lint_roller (1.1.0)
65
68
  listen (3.9.0)
66
69
  rb-fsevent (~> 0.10, >= 0.10.3)
67
70
  rb-inotify (~> 0.9, >= 0.9.10)
@@ -78,9 +81,10 @@ GEM
78
81
  notiffany (0.1.3)
79
82
  nenv (~> 0.1)
80
83
  shellany (~> 0.0)
81
- parallel (1.21.0)
82
- parser (3.0.2.0)
84
+ parallel (1.27.0)
85
+ parser (3.3.8.0)
83
86
  ast (~> 2.4.1)
87
+ racc
84
88
  pdf-core (0.10.0)
85
89
  pdf-inspector (1.3.0)
86
90
  pdf-reader (>= 1.0, < 3.0.a)
@@ -96,18 +100,17 @@ GEM
96
100
  ttfunk (~> 1.8)
97
101
  prawn-table (0.2.2)
98
102
  prawn (>= 1.3.0, < 3.0.0)
103
+ prism (1.4.0)
99
104
  pry (0.14.2)
100
105
  coderay (~> 1.1)
101
106
  method_source (~> 1.0)
102
107
  racc (1.8.1)
103
- rainbow (3.0.0)
108
+ rainbow (3.1.1)
104
109
  rake (13.2.1)
105
110
  rb-fsevent (0.11.2)
106
111
  rb-inotify (0.11.1)
107
112
  ffi (~> 1.0)
108
- regexp_parser (2.1.1)
109
- rexml (3.3.3)
110
- strscan
113
+ regexp_parser (2.10.0)
111
114
  rqrcode (2.2.0)
112
115
  chunky_png (~> 1.0)
113
116
  rqrcode_core (~> 1.0)
@@ -125,24 +128,34 @@ GEM
125
128
  diff-lcs (>= 1.2.0, < 2.0)
126
129
  rspec-support (~> 3.13.0)
127
130
  rspec-support (3.13.1)
128
- rubocop (0.93.1)
131
+ rubocop (1.75.3)
132
+ json (~> 2.3)
133
+ language_server-protocol (~> 3.17.0.2)
134
+ lint_roller (~> 1.1.0)
129
135
  parallel (~> 1.10)
130
- parser (>= 2.7.1.5)
136
+ parser (>= 3.3.0.2)
131
137
  rainbow (>= 2.2.2, < 4.0)
132
- regexp_parser (>= 1.8)
133
- rexml
134
- rubocop-ast (>= 0.6.0)
138
+ regexp_parser (>= 2.9.3, < 3.0)
139
+ rubocop-ast (>= 1.44.0, < 2.0)
135
140
  ruby-progressbar (~> 1.7)
136
- unicode-display_width (>= 1.4.0, < 2.0)
137
- rubocop-ast (1.13.0)
138
- parser (>= 3.0.1.1)
139
- rubocop-performance (1.10.2)
140
- rubocop (>= 0.90.0, < 2.0)
141
+ unicode-display_width (>= 2.4.0, < 4.0)
142
+ rubocop-ast (1.44.1)
143
+ parser (>= 3.3.7.2)
144
+ prism (~> 1.4)
145
+ rubocop-capybara (2.22.1)
146
+ lint_roller (~> 1.1)
147
+ rubocop (~> 1.72, >= 1.72.1)
148
+ rubocop-factory_bot (2.27.1)
149
+ lint_roller (~> 1.1)
150
+ rubocop (~> 1.72, >= 1.72.1)
151
+ rubocop-performance (1.19.1)
152
+ rubocop (>= 1.7.0, < 2.0)
141
153
  rubocop-ast (>= 0.4.0)
142
- rubocop-rspec (1.44.1)
143
- rubocop (~> 0.87)
144
- rubocop-ast (>= 0.7.1)
145
- ruby-progressbar (1.11.0)
154
+ rubocop-rspec (2.25.0)
155
+ rubocop (~> 1.40)
156
+ rubocop-capybara (~> 2.17)
157
+ rubocop-factory_bot (~> 2.22)
158
+ ruby-progressbar (1.13.0)
146
159
  ruby-rc4 (0.1.5)
147
160
  ruby2_keywords (0.0.5)
148
161
  shellany (0.0.1)
@@ -151,14 +164,18 @@ GEM
151
164
  simplecov-html (~> 0.11)
152
165
  simplecov_json_formatter (~> 0.1)
153
166
  simplecov-html (0.13.1)
167
+ simplecov-json (0.2.3)
168
+ json
169
+ simplecov
154
170
  simplecov_json_formatter (0.1.4)
155
- strscan (3.1.0)
156
171
  thor (1.3.2)
157
172
  ttfunk (1.8.0)
158
173
  bigdecimal (~> 3.1)
159
174
  tzinfo (2.0.6)
160
175
  concurrent-ruby (~> 1.0)
161
- unicode-display_width (1.8.0)
176
+ unicode-display_width (3.1.4)
177
+ unicode-emoji (~> 4.0, >= 4.0.4)
178
+ unicode-emoji (4.0.4)
162
179
 
163
180
  PLATFORMS
164
181
  ruby
@@ -171,11 +188,12 @@ DEPENDENCIES
171
188
  pdf-inspector (~> 1.3.0)
172
189
  rake (= 13.2.1)
173
190
  rspec (= 3.13.0)
174
- rubocop (~> 0.93.1)
175
- rubocop-performance (~> 1.10.2)
176
- rubocop-rspec (~> 1.44.1)
191
+ rubocop (~> 1.75.3)
192
+ rubocop-performance (~> 1.19.0)
193
+ rubocop-rspec (~> 2.25.0)
177
194
  simplecov (= 0.22.0)
178
195
  simplecov-html (= 0.13.1)
196
+ simplecov-json (= 0.2.3)
179
197
 
180
198
  BUNDLED WITH
181
199
  2.5.5
data/br_danfe.gemspec CHANGED
@@ -11,7 +11,6 @@ Gem::Specification.new do |spec|
11
11
  spec.license = 'MIT'
12
12
 
13
13
  spec.files = `git ls-files`.split("\n")
14
- spec.test_files = `git ls-files -- { test,spec,features }/*`.split("\n")
15
14
  spec.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
16
15
  spec.require_paths = ['lib']
17
16
  spec.required_ruby_version = '>= 3.0'
@@ -24,15 +23,5 @@ Gem::Specification.new do |spec|
24
23
  spec.add_dependency 'prawn-table', '0.2.2'
25
24
  spec.add_dependency 'rqrcode', '>= 2.1', '< 2.3'
26
25
 
27
- spec.add_development_dependency 'byebug', '11.1.3'
28
- spec.add_development_dependency 'guard', '~> 2.19.0'
29
- spec.add_development_dependency 'guard-rspec', '~> 4.7.3'
30
- spec.add_development_dependency 'pdf-inspector', '~> 1.3.0'
31
- spec.add_development_dependency 'rake', '13.2.1'
32
- spec.add_development_dependency 'rspec', '3.13.0'
33
- spec.add_development_dependency 'rubocop', '~> 0.93.1'
34
- spec.add_development_dependency 'rubocop-performance', '~> 1.10.2'
35
- spec.add_development_dependency 'rubocop-rspec', '~> 1.44.1'
36
- spec.add_development_dependency 'simplecov', '0.22.0'
37
- spec.add_development_dependency 'simplecov-html', '0.13.1'
26
+ spec.metadata['rubygems_mfa_required'] = 'true'
38
27
  end
@@ -47,7 +47,8 @@ pt-BR:
47
47
  IM: "INSCRIÇÃO MUNICIPAL"
48
48
  IE: "INSCRIÇÃO ESTADUAL"
49
49
  IEST: "INSC.ESTADUAL DO SUBST. TRIBUTÁRIO"
50
- CNPJ: "CNPJ"
50
+ CNPJ: "CNPJ/CPF"
51
+ CPF: "CNPJ/CPF"
51
52
  dup:
52
53
  title: "FATURA / DUPLICATAS"
53
54
  nDup: "NRO"
@@ -146,8 +147,8 @@ pt-BR:
146
147
  document: "NF-e\nN°. %{nNF}\nSÉRIE %{serie}"
147
148
  entrega:
148
149
  title: "INFORMAÇÕES DO LOCAL DE ENTREGA"
149
- CNPJ: "CNPJ"
150
- CPF: "CPF"
150
+ CNPJ: "CNPJ/CPF"
151
+ CPF: "CNPJ/CPF"
151
152
  xNome: "NOME/RAZÃO SOCIAL"
152
153
  xLgr: "ENDEREÇO"
153
154
  nro: "NÚMERO"
@@ -15,9 +15,9 @@ module BrDanfe
15
15
  @document.line_width = 0.3
16
16
  end
17
17
 
18
- def method_missing(method_name, *args, &block)
18
+ def method_missing(method_name, ...)
19
19
  if @document.respond_to? method_name
20
- @document.send method_name, *args, &block
20
+ @document.send(method_name, ...)
21
21
  else
22
22
  super
23
23
  end
@@ -20,9 +20,9 @@ module BrDanfe
20
20
  @document.text ' ', size: font_size
21
21
  end
22
22
 
23
- def method_missing(method_name, *args, &block)
23
+ def method_missing(method_name, ...)
24
24
  if @document.respond_to? method_name
25
- @document.send method_name, *args, &block
25
+ @document.send(method_name, ...)
26
26
  else
27
27
  super
28
28
  end
@@ -24,7 +24,7 @@ module BrDanfe
24
24
  def render_company_info
25
25
  one_line = 1
26
26
 
27
- @pdf.text_box (@xml['emit/xNome']).to_s, at: [x_position, @pdf.cursor], height: 36, size: 9, align: :left, style: :bold, overflow: :shrink_to_fit
27
+ @pdf.text_box @xml['emit/xNome'].to_s, at: [x_position, @pdf.cursor], height: 36, size: 9, align: :left, style: :bold, overflow: :shrink_to_fit
28
28
  @pdf.move_down 36
29
29
 
30
30
  @pdf.text_box cnpj(@xml['emit/CNPJ']), at: [x_position, @pdf.cursor], height: 9, size: 9, align: :left, overflow: :shrink_to_fit
@@ -34,16 +34,8 @@ module BrDanfe
34
34
  end
35
35
 
36
36
  def render_cnpj_cpf
37
- if @xml['dest/CNPJ'] == ''
38
- @pdf.i18n_lbox LINE_HEIGHT, 4.37, 12.57, @l1, 'dest.CPF', cpf
39
- else
40
- @pdf.lcnpj LINE_HEIGHT, 4.37, 12.57, @l1, @xml, 'dest/CNPJ'
41
- end
42
- end
43
-
44
- def cpf
45
- cpf = BrDocuments::CnpjCpf::Cpf.new(@xml['dest/CPF'])
46
- cpf.formatted
37
+ xpath = @xml['dest/CNPJ'].present? ? 'dest/CNPJ' : 'dest/CPF'
38
+ @pdf.lcnpj_cpf LINE_HEIGHT, 4.37, 12.57, @l1, @xml, xpath
47
39
  end
48
40
 
49
41
  def render_line2
@@ -17,9 +17,9 @@ module BrDanfe
17
17
  @document.line_width = 0.3
18
18
  end
19
19
 
20
- def method_missing(method_name, *args, &block)
20
+ def method_missing(method_name, ...)
21
21
  if @document.respond_to? method_name
22
- @document.send method_name, *args, &block
22
+ @document.send(method_name, ...)
23
23
  else
24
24
  super
25
25
  end
@@ -64,12 +64,12 @@ module BrDanfe
64
64
  i18n_lbox(h, w, x, y, i18n, data, options)
65
65
  end
66
66
 
67
- def lcnpj(h, w, x, y, xml, xpath, options = {})
67
+ def lcnpj_cpf(h, w, x, y, xml, xpath, options = {})
68
68
  i18n = xpath.tr('/', '.')
69
-
70
- cnpj = BrDocuments::CnpjCpf::Cnpj.new(xml[xpath])
71
- data = if cnpj.valid?
72
- cnpj.formatted
69
+ document_class = xpath.include?('CNPJ') ? BrDocuments::CnpjCpf::Cnpj : BrDocuments::CnpjCpf::Cpf
70
+ cnpj_cpf = document_class.new(xml[xpath])
71
+ data = if cnpj_cpf.valid?
72
+ cnpj_cpf.formatted
73
73
  else
74
74
  ''
75
75
  end
@@ -97,12 +97,12 @@ module BrDanfe
97
97
  end
98
98
 
99
99
  def inumeric(h, w, x, y, i18n = '', data = '', options = {})
100
- label = i18n != '' ? I18n.t("danfe.#{i18n}") : ''
100
+ label = i18n == '' ? '' : I18n.t("danfe.#{i18n}")
101
101
  numeric [x.cm, Helper.invert(y.cm)], w.cm, h.cm, label, data, options
102
102
  end
103
103
 
104
104
  def i18n_lbox(h, w, x, y, i18n = '', info = '', options = {})
105
- label = i18n != '' ? I18n.t("danfe.#{i18n}") : ''
105
+ label = i18n == '' ? '' : I18n.t("danfe.#{i18n}")
106
106
  ibox h, w, x, y, label, info, options
107
107
  end
108
108
 
@@ -108,7 +108,15 @@ module BrDanfe
108
108
 
109
109
  @pdf.lie LINE_HEIGHT, 6.36, 0.75, y_second_line, @xml, 'enderEmit/UF', 'emit/IE'
110
110
  @pdf.lie LINE_HEIGHT, 6.86, 7.11, y_second_line, @xml, 'enderDest/UF', 'emit/IEST'
111
- @pdf.lcnpj LINE_HEIGHT, 6.34, 13.97, y_second_line, @xml, 'emit/CNPJ'
111
+ @pdf.lcnpj_cpf LINE_HEIGHT, 6.34, 13.97, y_second_line, @xml, cnpj_cpf
112
+ end
113
+
114
+ def cnpj_cpf
115
+ if @xml['emit/CNPJ'].present?
116
+ 'emit/CNPJ'
117
+ else
118
+ 'emit/CPF'
119
+ end
112
120
  end
113
121
  end
114
122
  end
@@ -39,16 +39,8 @@ module BrDanfe
39
39
  end
40
40
 
41
41
  def render_cnpj_cpf
42
- if @xml['entrega/CNPJ'] == ''
43
- @pdf.i18n_lbox LINE_HEIGHT, 4.37, 12.57, @l1, 'entrega.CPF', cpf
44
- else
45
- @pdf.lcnpj LINE_HEIGHT, 4.37, 12.57, @l1, @xml, 'entrega/CNPJ'
46
- end
47
- end
48
-
49
- def cpf
50
- cpf = BrDocuments::CnpjCpf::Cpf.new(@xml['entrega/CPF'])
51
- cpf.formatted
42
+ xpath = @xml['entrega/CNPJ'].present? ? 'entrega/CNPJ' : 'entrega/CPF'
43
+ @pdf.lcnpj_cpf LINE_HEIGHT, 4.37, 12.57, @l1, @xml, xpath
52
44
  end
53
45
 
54
46
  def render_line2
@@ -113,7 +113,7 @@ module BrDanfe
113
113
 
114
114
  def generate_y_position(volumes_number)
115
115
  if volumes_number > 1
116
- return Y_POSITION + 0.30 + volumes_number * 0.15 + 0.2
116
+ return Y_POSITION + 0.30 + (volumes_number * 0.15) + 0.2
117
117
  end
118
118
 
119
119
  Y_POSITION + 0.30
@@ -25,7 +25,7 @@ module BrDanfe
25
25
  @pdf.lbox LINE_HEIGHT, 1.78, 12.06, @l1, @xml, 'veicTransp/RNTC'
26
26
  @pdf.i18n_lbox LINE_HEIGHT, 2.29, 13.84, @l1, 'veicTransp.placa', plate
27
27
  @pdf.lbox LINE_HEIGHT, 0.76, 16.13, @l1, @xml, 'veicTransp/UF'
28
- @pdf.lcnpj LINE_HEIGHT, 3.44, 16.89, @l1, @xml, 'transporta/CNPJ'
28
+ @pdf.lcnpj_cpf LINE_HEIGHT, 3.44, 16.89, @l1, @xml, 'transporta/CNPJ'
29
29
  @pdf.lbox LINE_HEIGHT, 8.52, 0.75, @l2, @xml, 'transporta/xEnder'
30
30
  @pdf.lbox LINE_HEIGHT, 6.86, 9.27, @l2, @xml, 'transporta/xMun'
31
31
  @pdf.lbox LINE_HEIGHT, 0.76, 16.13, @l2, @xml, 'transporta/UF'
@@ -1,7 +1,7 @@
1
1
  module BrDanfe
2
2
  class DocumentBuilder
3
- def self.build(*args, &block)
4
- document = Prawn::Document.new(*args, &block)
3
+ def self.build(...)
4
+ document = Prawn::Document.new(...)
5
5
 
6
6
  document.font_families['tinos'] = {
7
7
  bold: "#{BrDanfe.root_path}/fonts/tinos_bold.ttf",
@@ -21,7 +21,7 @@ module BrDanfe
21
21
  end
22
22
 
23
23
  def calculate_size(size)
24
- size < @bounding_box_size ? size : @bounding_box_size
24
+ [size, @bounding_box_size].min
25
25
  end
26
26
  end
27
27
  end
@@ -10,9 +10,9 @@ module BrDanfe
10
10
  @document.font 'tinos'
11
11
  end
12
12
 
13
- def method_missing(method_name, *args, &block)
13
+ def method_missing(method_name, ...)
14
14
  if @document.respond_to? method_name
15
- @document.send method_name, *args, &block
15
+ @document.send(method_name, ...)
16
16
  else
17
17
  super
18
18
  end
@@ -1,3 +1,3 @@
1
1
  module BrDanfe
2
- VERSION = '1.2.3'.freeze
2
+ VERSION = '2.1.0'.freeze
3
3
  end
data/lib/br_danfe.rb CHANGED
@@ -9,7 +9,7 @@ require 'yaml'
9
9
  require 'i18n'
10
10
  require 'br_documents'
11
11
 
12
- Dir["#{File.dirname(__FILE__)}/**/*.rb"].sort.each { |f| require f }
12
+ Dir["#{File.dirname(__FILE__)}/**/*.rb"].sort.each { |f| require f } # rubocop:disable Lint/RedundantDirGlobSort
13
13
 
14
14
  I18n.load_path << File.expand_path('../config/locales/pt-BR.yml', __dir__)
15
15
  I18n.available_locales = ['pt-BR']
data/lib/prawn/font.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Prawn
2
2
  class Font
3
- def hash #:nodoc:
3
+ def hash # :nodoc:
4
4
  [self.class, name, family].hash
5
5
  end
6
6
  end
@@ -12,7 +12,7 @@ describe BrDanfe::CceLib::Barcode do
12
12
  describe '#render' do
13
13
  before do
14
14
  subject.render
15
- File.delete(output_pdf) if File.exist?(output_pdf)
15
+ FileUtils.rm_f(output_pdf)
16
16
  end
17
17
 
18
18
  it 'renders header to the pdf' do
@@ -12,7 +12,7 @@ describe BrDanfe::CceLib::Correction do
12
12
  describe '#render' do
13
13
  before do
14
14
  subject.render
15
- File.delete(output_pdf) if File.exist?(output_pdf)
15
+ FileUtils.rm_f(output_pdf)
16
16
  end
17
17
 
18
18
  it 'renders header to the pdf' do
@@ -7,7 +7,7 @@ describe BrDanfe::CceLib::Document do
7
7
  describe '#box' do
8
8
  context "when a block isn't passed" do
9
9
  before do
10
- File.delete(output_pdf) if File.exist?(output_pdf)
10
+ FileUtils.rm_f(output_pdf)
11
11
  subject.box(height: 50)
12
12
  end
13
13
 
@@ -22,7 +22,7 @@ describe BrDanfe::CceLib::Document do
22
22
 
23
23
  context 'when a block is passed' do
24
24
  before do
25
- File.delete(output_pdf) if File.exist?(output_pdf)
25
+ FileUtils.rm_f(output_pdf)
26
26
  subject.box(height: 50) { subject.text 'sample text' }
27
27
  end
28
28
 
@@ -39,7 +39,7 @@ describe BrDanfe::CceLib::Document do
39
39
  describe '#text' do
40
40
  context 'when is a simple text' do
41
41
  before do
42
- File.delete(output_pdf) if File.exist?(output_pdf)
42
+ FileUtils.rm_f(output_pdf)
43
43
  subject.text 'simple text'
44
44
  end
45
45
 
@@ -54,7 +54,7 @@ describe BrDanfe::CceLib::Document do
54
54
 
55
55
  context 'when is a text with style' do
56
56
  before do
57
- File.delete(output_pdf) if File.exist?(output_pdf)
57
+ FileUtils.rm_f(output_pdf)
58
58
  subject.text 'bold text', style: :bold
59
59
  end
60
60
 
@@ -69,7 +69,7 @@ describe BrDanfe::CceLib::Document do
69
69
 
70
70
  context 'when is a text with size' do
71
71
  before do
72
- File.delete(output_pdf) if File.exist?(output_pdf)
72
+ FileUtils.rm_f(output_pdf)
73
73
  subject.text 'big text', size: 25
74
74
  end
75
75
 
@@ -84,7 +84,7 @@ describe BrDanfe::CceLib::Document do
84
84
 
85
85
  context 'when is a text with pad' do
86
86
  before do
87
- File.delete(output_pdf) if File.exist?(output_pdf)
87
+ FileUtils.rm_f(output_pdf)
88
88
  subject.text 'text with pad', pad: 50
89
89
  end
90
90
 
@@ -99,7 +99,7 @@ describe BrDanfe::CceLib::Document do
99
99
 
100
100
  context 'when is a text with align' do
101
101
  before do
102
- File.delete(output_pdf) if File.exist?(output_pdf)
102
+ FileUtils.rm_f(output_pdf)
103
103
  subject.text 'text in center', align: :center
104
104
  end
105
105
 
@@ -11,7 +11,7 @@ describe BrDanfe::CceLib::Footer do
11
11
  describe '#render' do
12
12
  before do
13
13
  subject.render
14
- File.delete(output_pdf) if File.exist?(output_pdf)
14
+ FileUtils.rm_f(output_pdf)
15
15
  end
16
16
 
17
17
  it 'renders header to the pdf' do
@@ -11,7 +11,7 @@ describe BrDanfe::CceLib::Header do
11
11
  describe '#render' do
12
12
  before do
13
13
  subject.render
14
- File.delete(output_pdf) if File.exist?(output_pdf)
14
+ FileUtils.rm_f(output_pdf)
15
15
  end
16
16
 
17
17
  it 'renders header to the pdf' do
@@ -12,7 +12,7 @@ describe BrDanfe::CceLib::NfeKey do
12
12
  describe '#render' do
13
13
  before do
14
14
  subject.render
15
- File.delete(output_pdf) if File.exist?(output_pdf)
15
+ FileUtils.rm_f(output_pdf)
16
16
  end
17
17
 
18
18
  it 'renders header to the pdf' do
@@ -12,7 +12,7 @@ describe BrDanfe::CceLib::Protocol do
12
12
  describe '#render' do
13
13
  before do
14
14
  subject.render
15
- File.delete(output_pdf) if File.exist?(output_pdf)
15
+ FileUtils.rm_f(output_pdf)
16
16
  end
17
17
 
18
18
  it 'renders header to the pdf' do
@@ -8,14 +8,14 @@ describe BrDanfe::Cce do
8
8
 
9
9
  describe '#render_pdf' do
10
10
  it 'renders the correction letter' do
11
- expected = IO.binread("#{base_dir}cce.fixture.pdf")
11
+ expected = File.binread("#{base_dir}cce.fixture.pdf")
12
12
 
13
13
  expect(subject.render_pdf).to eq expected
14
14
  end
15
15
  end
16
16
 
17
17
  describe '#save_pdf' do
18
- before { File.delete(output_pdf) if File.exist?(output_pdf) }
18
+ before { FileUtils.rm_f(output_pdf) }
19
19
 
20
20
  it 'saves the pdf' do
21
21
  expect(File.exist?(output_pdf)).to be_falsey
@@ -6,7 +6,7 @@ describe BrDanfe::DanfeLib::NfceLib::ProductList do
6
6
 
7
7
  let(:subject) { BrDanfe::DanfeLib::NfceLib::Document.new(8.cm, 1.8.cm) }
8
8
 
9
- before { File.delete(output_pdf) if File.exist?(output_pdf) }
9
+ before { FileUtils.rm_f(output_pdf) }
10
10
 
11
11
  it 'render the document with blank lines' do
12
12
  expect(File.exist?(output_pdf)).to be_falsey
@@ -27,7 +27,7 @@ describe BrDanfe::DanfeLib::NfceLib::Footer do
27
27
  subject { described_class.new pdf, xml_footer }
28
28
 
29
29
  describe '#render' do
30
- before { File.delete(output_pdf) if File.exist?(output_pdf) }
30
+ before { FileUtils.rm_f(output_pdf) }
31
31
 
32
32
  it 'renders footer to the pdf' do
33
33
  subject.render
@@ -49,10 +49,10 @@ describe BrDanfe::DanfeLib::NfceLib::Header do
49
49
  describe '#render' do
50
50
  before do
51
51
  subject.render
52
- File.delete(output_pdf) if File.exist?(output_pdf)
52
+ FileUtils.rm_f(output_pdf)
53
53
  end
54
54
 
55
- after { File.delete(output_pdf) if File.exist?(output_pdf) }
55
+ after { FileUtils.rm_f(output_pdf) }
56
56
 
57
57
  context 'when has a short name' do
58
58
  let(:company_name) { 'Test company' }