teodoro 0.0.5 → 0.0.10

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 388cf870f613b44db893f7dc59c617e488147e4748300010b49aa9fed806561f
4
- data.tar.gz: 02a2cc0a45845fe3a91ab3c99654de22e50dca2a3ecd7bfd2978730639e98103
3
+ metadata.gz: 6813c49b858cd3dd4f2732bf76c0ca99c465e3ee55b713773595206b038048b4
4
+ data.tar.gz: 306eb583e7c68f82cb5fbb9aa0a7983a108a82c8b37e5283c9f54d519a53ad22
5
5
  SHA512:
6
- metadata.gz: 8fee82578abb11884fcebdd5053bb352e06449433430ba523a5f95fd24be9f5be6825c78621570453c909c657edd35e71aeddf99fcdc985cbb681cf745e02df7
7
- data.tar.gz: 6f82377f839a4cd026ad954b4825adbe39ca1bf7d0c58927520fda62f7c0bd26c29098ef8314a814abb811f144728e3de1d415a86d5f2e32ce05921420a42256
6
+ metadata.gz: cda354fd4d76b448b763ab5b447b40122c8c9e7dbbe874c81ead7e1b6cb218dfebe983f255443887ceb8901808ca213674def5e6022b25c086c3abefc54edb71
7
+ data.tar.gz: aa311e5876f76f91c818f250a3f12908173ced56a8722a0db14fa85b17b2fbb4cb8abda34c302a19ea023e54d1a8cd5372ae479d23fbea7b1ab9376f8624fc81
data/bin/teodoro CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'teodoro'
3
- Teodoro.call
3
+ Teodoro.call(ARGV)
data/lib/teodoro.rb CHANGED
@@ -1,7 +1,81 @@
1
- require_relative 'teodoro/execucao'
1
+ require 'nokogiri'
2
+ require 'os'
3
+ require 'zip'
4
+
5
+ require_relative 'teodoro/console'
6
+ require_relative 'teodoro/empresa'
2
7
 
3
8
  module Teodoro
4
- def self.call
5
- Execucao.new(origem: ARGV[0], destino: ARGV[1]).call
9
+ def self.call(args)
10
+ Execution.new(args).call
11
+ end
12
+
13
+ class Execution
14
+ NOME_DO_PROGRAMA = 'teodoro'.freeze
15
+
16
+ private
17
+
18
+ def initialize(args)
19
+ @args = args
20
+ end
21
+
22
+ attr_reader :args
23
+
24
+ public
25
+
26
+ def call
27
+ executar
28
+ rescue StandardError => e
29
+ Console.print e.message, *e.backtrace, color: :red
30
+ exit
31
+ end
32
+
33
+ private
34
+
35
+ def executar
36
+ validar_argumentos
37
+ validar_existencia_do_diretorio_de_origem
38
+ validar_que_diretorio_de_origem_nao_esta_vazio
39
+ validar_que_diretorio_de_destino_esta_vazio
40
+
41
+ processar_empresas
42
+ end
43
+
44
+ def validar_argumentos
45
+ erro "#{NOME_DO_PROGRAMA} [diretório de origem] [diretório de destino]" unless args.size == 2
46
+ end
47
+
48
+ def validar_existencia_do_diretorio_de_origem
49
+ erro 'Diretório de origem não existe.' unless File.directory?(origem)
50
+ end
51
+
52
+ def origem
53
+ @origem ||= args[0]
54
+ end
55
+
56
+ def validar_que_diretorio_de_origem_nao_esta_vazio
57
+ erro 'Diretório de origem vazio.' if Dir.empty?(origem)
58
+ end
59
+
60
+ def validar_que_diretorio_de_destino_esta_vazio
61
+ erro 'Diretório de destino deve estar vazio.' unless Dir.empty?(destino)
62
+ end
63
+
64
+ def destino
65
+ @destino ||= args[1]
66
+ end
67
+
68
+ def erro(erro)
69
+ puts erro
70
+ exit
71
+ end
72
+
73
+ def processar_empresas
74
+ empresas.each(&:processar)
75
+ end
76
+
77
+ def empresas
78
+ Dir[File.join(origem, '*')].map { |caminho| Empresa.new(caminho: caminho, destino: destino) }
79
+ end
6
80
  end
7
81
  end
@@ -2,30 +2,17 @@ module Teodoro
2
2
  module ArquivoDeEvento
3
3
  private
4
4
 
5
- attr_reader :xml_do_evento, :xml_do_recibo, :destino_dos_arquivos_data
5
+ attr_reader :evento, :destino_dos_arquivos_data
6
6
 
7
- def criar_arquivo_data
8
- File.write(caminho_do_arquivo_data, conteudo_do_arquivo_data)
7
+ def criar_caminho_do_arquivo_data(nome_do_arquivo)
8
+ File.join(
9
+ destino_dos_arquivos_data,
10
+ "#{windows? ? nome_do_arquivo.gsub(%r{[<|>:"/\\?*]}, '_') : nome_do_arquivo}.data"
11
+ )
9
12
  end
10
13
 
11
- def evento
12
- @evento ||= XML.new(xml_do_evento)
13
- end
14
-
15
- def conteudo_do_arquivo_data
16
- (itens_do_conteudo_do_arquivo_data.map { "#{_1}=#{_2}" } + ['']).join("\n")
17
- end
18
-
19
- def versao_do_aplicativo_de_processamento_do_evento
20
- recibo['retornoEvento/processamento/versaoAppProcessamento']
21
- end
22
-
23
- def tipo_de_inscricao_do_empregador
24
- @tipo_de_inscricao_do_empregador ||= evento["#{noh_principal_do_evento}/ideEmpregador/tpInsc"]
25
- end
26
-
27
- def recibo
28
- @recibo ||= XML.new(xml_do_recibo)
14
+ def windows?
15
+ OS.windows?
29
16
  end
30
17
  end
31
18
  end
@@ -1,12 +1,12 @@
1
1
  module Teodoro
2
2
  module ArquivoDeEventoDeTabela
3
- include ArquivoDeEvento
3
+ include ArquivoDeEventoExcetoDeExclusao
4
4
 
5
5
  private
6
6
 
7
- def initialize(xml_do_evento:, xml_do_recibo:, destino_dos_arquivos_data:)
8
- @xml_do_evento = xml_do_evento
9
- @xml_do_recibo = xml_do_recibo
7
+ def initialize(evento:, recibo:, destino_dos_arquivos_data:)
8
+ @evento = evento
9
+ @recibo = recibo
10
10
  @destino_dos_arquivos_data = destino_dos_arquivos_data
11
11
  end
12
12
 
@@ -38,10 +38,7 @@ module Teodoro
38
38
  end
39
39
 
40
40
  def obter_caminho_do_arquivo_data(inicio_da_validade)
41
- File.join(
42
- destino_dos_arquivos_data,
43
- "#{nome_base_do_arquivo_data}[#{inicio_da_validade.delete('-')}].data"
44
- )
41
+ criar_caminho_do_arquivo_data("#{nome_base_do_arquivo_data}[#{inicio_da_validade.delete('-')}]")
45
42
  end
46
43
 
47
44
  def nome_base_do_arquivo_data
@@ -0,0 +1,27 @@
1
+ module Teodoro
2
+ module ArquivoDeEventoExcetoDeExclusao
3
+ include ArquivoDeEvento
4
+
5
+ private
6
+
7
+ attr_reader :recibo
8
+
9
+ def criar_arquivo_data
10
+ raise caminho_do_arquivo_data if File.exist?(caminho_do_arquivo_data)
11
+
12
+ File.write(caminho_do_arquivo_data, conteudo_do_arquivo_data)
13
+ end
14
+
15
+ def conteudo_do_arquivo_data
16
+ (itens_do_conteudo_do_arquivo_data.map { "#{_1}=#{_2}" } + ['']).join("\n")
17
+ end
18
+
19
+ def versao_do_aplicativo_de_processamento_do_evento
20
+ recibo['retornoEvento/processamento/versaoAppProcessamento']
21
+ end
22
+
23
+ def tipo_de_inscricao_do_empregador
24
+ @tipo_de_inscricao_do_empregador ||= evento["#{noh_principal_do_evento}/ideEmpregador/tpInsc"]
25
+ end
26
+ end
27
+ end
@@ -1,12 +1,12 @@
1
1
  module Teodoro
2
2
  module ArquivoDeEventoNaoPeriodico
3
- include ArquivoDeEvento
3
+ include ArquivoDeEventoExcetoDeExclusao
4
4
 
5
5
  private
6
6
 
7
- def initialize(xml_do_evento:, xml_do_recibo:, destino_dos_arquivos_data:, de_recibo_para_nome_do_arquivo_data:)
8
- @xml_do_evento = xml_do_evento
9
- @xml_do_recibo = xml_do_recibo
7
+ def initialize(evento:, recibo:, destino_dos_arquivos_data:, de_recibo_para_nome_do_arquivo_data:)
8
+ @evento = evento
9
+ @recibo = recibo
10
10
  @destino_dos_arquivos_data = destino_dos_arquivos_data
11
11
  @de_recibo_para_nome_do_arquivo_data = de_recibo_para_nome_do_arquivo_data
12
12
  end
@@ -32,7 +32,7 @@ module Teodoro
32
32
  end
33
33
 
34
34
  def caminho_do_arquivo_data_original
35
- File.join(destino_dos_arquivos_data, "#{nome_do_arquivo_original}.data")
35
+ criar_caminho_do_arquivo_data(nome_do_arquivo_original)
36
36
  end
37
37
 
38
38
  def nome_do_arquivo_original
@@ -52,7 +52,7 @@ module Teodoro
52
52
  end
53
53
 
54
54
  def caminho_do_arquivo_data
55
- File.join(destino_dos_arquivos_data, "#{nome_do_arquivo_data}.data")
55
+ criar_caminho_do_arquivo_data(nome_do_arquivo_data)
56
56
  end
57
57
  end
58
58
  end
@@ -14,7 +14,7 @@ module Teodoro
14
14
  public
15
15
 
16
16
  def descompactar
17
- puts File.basename(caminho)
17
+ print "\e[2Kdescompactando #{File.basename(caminho)}...\r"
18
18
 
19
19
  Zip::File.open(caminho) do |zip|
20
20
  zip
@@ -1,4 +1,5 @@
1
1
  require_relative 'arquivo_de_evento'
2
+ require_relative 'arquivo_de_evento_exceto_de_exclusao'
2
3
  require_relative 'arquivo_de_evento_de_tabela'
3
4
  require_relative 'arquivo_de_evento_nao_periodico'
4
5
  require_relative 'cnpj'
@@ -6,7 +7,27 @@ require_relative 'leiaute_2_4_1'
6
7
  require_relative 'xml'
7
8
 
8
9
  module Teodoro
9
- class ArquivoXML
10
+ class ArquivoXML # rubocop:disable Metrics/ClassLength
11
+ TIPOS_DE_EVENTO_PROCESSAVEIS = %w[
12
+ S1000
13
+ S1005
14
+ S1010
15
+ S1020
16
+ S1030
17
+ S1040
18
+ S1050
19
+ S1070
20
+ S2190
21
+ S2200
22
+ S2205
23
+ S2206
24
+ S2230
25
+ S2250
26
+ S2300
27
+ S2306
28
+ S3000
29
+ ].freeze
30
+
10
31
  private
11
32
 
12
33
  def initialize(caminho:, destino_dos_arquivos_data:, de_recibo_para_nome_do_arquivo_data:)
@@ -19,21 +40,31 @@ module Teodoro
19
40
 
20
41
  public
21
42
 
43
+ def momento_de_processamento_pelo_e_social
44
+ # otimizacao do gerenciamento de memoria
45
+ carregar_conteudo
46
+ .then { |conteudo| Nokogiri::XML(conteudo) }
47
+ .then { |xml| Nokogiri::XML(xml.css('eSocial/retornoProcessamentoDownload/recibo/*').to_s) }
48
+ .then { |xml_do_recibo| XML.new(xml_do_recibo) }
49
+ .then { |recibo| recibo['retornoEvento/processamento/dhProcessamento'] }
50
+ end
51
+
22
52
  def nome
23
53
  @nome ||= File.basename(caminho, '.xml')
24
54
  end
25
55
 
26
56
  def processar
27
- return unless %w[S1000 S1005 S1010 S1020 S1030 S1040 S1050 S1070 S2190 S2200 S2205 S2206 S2230 S2250 S2300 S2306]
28
- .include?(tipo_de_evento)
57
+ print "\e[2Kprocessando #{nome}.xml...\r"
58
+
59
+ return unless TIPOS_DE_EVENTO_PROCESSAVEIS.include?(tipo_de_evento)
29
60
 
30
61
  arquivo.processar
31
62
  end
32
63
 
33
64
  private
34
65
 
35
- def tipo_de_evento
36
- nome[-6..].delete('-')
66
+ def carregar_conteudo
67
+ File.read(caminho)
37
68
  end
38
69
 
39
70
  def arquivo
@@ -41,6 +72,8 @@ module Teodoro
41
72
  evento_de_tabela
42
73
  elsif evento_nao_periodico?
43
74
  evento_nao_periodico
75
+ elsif evento_de_exclusao?
76
+ evento_de_exclusao
44
77
  end
45
78
  end
46
79
 
@@ -50,8 +83,8 @@ module Teodoro
50
83
 
51
84
  def evento_de_tabela
52
85
  classe_do_arquivo.new(
53
- xml_do_evento: xml_do_evento,
54
- xml_do_recibo: xml_do_recibo,
86
+ evento: evento,
87
+ recibo: recibo,
55
88
  destino_dos_arquivos_data: destino_dos_arquivos_data
56
89
  )
57
90
  end
@@ -62,13 +95,25 @@ module Teodoro
62
95
 
63
96
  def evento_nao_periodico
64
97
  classe_do_arquivo.new(
65
- xml_do_evento: xml_do_evento,
66
- xml_do_recibo: xml_do_recibo,
98
+ evento: evento,
99
+ recibo: recibo,
67
100
  destino_dos_arquivos_data: destino_dos_arquivos_data,
68
101
  de_recibo_para_nome_do_arquivo_data: de_recibo_para_nome_do_arquivo_data
69
102
  )
70
103
  end
71
104
 
105
+ def evento_de_exclusao?
106
+ tipo_de_evento == 'S3000'
107
+ end
108
+
109
+ def evento_de_exclusao
110
+ classe_do_arquivo.new(
111
+ evento: evento,
112
+ de_recibo_para_nome_do_arquivo_data: de_recibo_para_nome_do_arquivo_data,
113
+ destino_dos_arquivos_data: destino_dos_arquivos_data
114
+ )
115
+ end
116
+
72
117
  def classe_do_arquivo
73
118
  modulo_do_leiaute.const_get("Arquivo#{tipo_de_evento}")
74
119
  end
@@ -95,18 +140,23 @@ module Teodoro
95
140
  end
96
141
 
97
142
  def xml
98
- @xml ||= Nokogiri::XML(conteudo)
143
+ @xml ||= Nokogiri::XML(carregar_conteudo)
99
144
  end
100
145
 
101
- def conteudo
102
- File.read(caminho)
146
+ def tipo_de_evento
147
+ @tipo_de_evento ||= nome[-6..].delete('-')
103
148
  end
104
149
 
105
- def xml_do_recibo
106
- Nokogiri::XML(xml.css('eSocial/retornoProcessamentoDownload/recibo/*').to_s)
150
+ def evento
151
+ XML.new(xml_do_evento)
152
+ end
153
+
154
+ def recibo
155
+ @recibo ||= XML.new(xml_do_recibo)
107
156
  end
108
157
 
109
- module Base
158
+ def xml_do_recibo
159
+ Nokogiri::XML(xml.css('eSocial/retornoProcessamentoDownload/recibo/*').to_s)
110
160
  end
111
161
  end
112
162
  end
@@ -21,12 +21,12 @@ module Teodoro
21
21
  descompactar_arquivos_de_origem
22
22
  criar_diretorio_dos_arquivos_data
23
23
  processar_arquivos_xml
24
+ limpar_linha_de_feedback
24
25
  end
25
26
 
26
27
  private
27
28
 
28
29
  def dar_feedback_para_o_usuario
29
- puts ''
30
30
  Console.print nome_do_diretorio, color: :green
31
31
  end
32
32
 
@@ -64,11 +64,13 @@ module Teodoro
64
64
  end
65
65
 
66
66
  def processar_arquivos_xml
67
- arquivos_xml.each(&:processar)
67
+ # otimizacao do gerenciamento de memoria
68
+ arquivos_xml.shift.processar while arquivos_xml.any?
68
69
  end
69
70
 
70
71
  def arquivos_xml
71
- Dir[File.join(destino_dos_arquivos_xml, '*.xml')]
72
+ @arquivos_xml ||=
73
+ Dir[File.join(destino_dos_arquivos_xml, '*.xml')]
72
74
  .map do |caminho|
73
75
  ArquivoXML.new(
74
76
  caminho: caminho,
@@ -76,10 +78,15 @@ module Teodoro
76
78
  de_recibo_para_nome_do_arquivo_data: de_recibo_para_nome_do_arquivo_data
77
79
  )
78
80
  end
81
+ .sort_by { [_1.momento_de_processamento_pelo_e_social, _1.nome] }
79
82
  end
80
83
 
81
84
  def de_recibo_para_nome_do_arquivo_data
82
85
  @de_recibo_para_nome_do_arquivo_data ||= {}
83
86
  end
87
+
88
+ def limpar_linha_de_feedback
89
+ print "\e[2K"
90
+ end
84
91
  end
85
92
  end
@@ -14,6 +14,7 @@ require_relative 'leiaute_2_4_1/arquivo_s2230'
14
14
  require_relative 'leiaute_2_4_1/arquivo_s2250'
15
15
  require_relative 'leiaute_2_4_1/arquivo_s2300'
16
16
  require_relative 'leiaute_2_4_1/arquivo_s2306'
17
+ require_relative 'leiaute_2_4_1/arquivo_s3000'
17
18
 
18
19
  module Teodoro
19
20
  module Leiaute_2_4_1
@@ -18,7 +18,11 @@ module Teodoro
18
18
  end
19
19
 
20
20
  def identificacao_do_arquivo_data
21
- ['RUB', codigo]
21
+ ['RUB', "#{identificador_da_tabela_de_rubricas}_#{codigo}"] # FIXME: Tales
22
+ end
23
+
24
+ def identificador_da_tabela_de_rubricas
25
+ @identificador_da_tabela_de_rubricas ||= evento['evtTabRubrica/infoRubrica/*/ideRubrica/ideTabRubr']
22
26
  end
23
27
 
24
28
  def codigo
@@ -36,7 +40,7 @@ module Teodoro
36
40
  ['InicioValidade', inicio_da_validade],
37
41
  ['FimValidade', fim_da_validade],
38
42
  ['chkIdTabelaRubrica'],
39
- ['IdTabelaRubrica', evento['evtTabRubrica/infoRubrica/*/ideRubrica/ideTabRubr']],
43
+ ['IdTabelaRubrica', identificador_da_tabela_de_rubricas],
40
44
  ['IdTabelaRubricaText'],
41
45
  ['DadosRubrica_Descricao', evento['evtTabRubrica/infoRubrica/*/dadosRubrica/dscRubr']],
42
46
  ['DadosRubrica_Natureza', evento['evtTabRubrica/infoRubrica/*/dadosRubrica/natRubr']],
@@ -0,0 +1,45 @@
1
+ module Teodoro
2
+ module Leiaute_2_4_1
3
+ class ArquivoS3000
4
+ include ArquivoDeEvento
5
+
6
+ private
7
+
8
+ def initialize(evento:, de_recibo_para_nome_do_arquivo_data:, destino_dos_arquivos_data:)
9
+ @evento = evento
10
+ @de_recibo_para_nome_do_arquivo_data = de_recibo_para_nome_do_arquivo_data
11
+ @destino_dos_arquivos_data = destino_dos_arquivos_data
12
+ end
13
+
14
+ attr_reader :de_recibo_para_nome_do_arquivo_data
15
+
16
+ public
17
+
18
+ def processar
19
+ excluir_arquivo_data_original if tipo_de_evento_processaveis?
20
+ end
21
+
22
+ private
23
+
24
+ def tipo_de_evento_processaveis?
25
+ ArquivoXML::TIPOS_DE_EVENTO_PROCESSAVEIS.include?(tipo_de_evento)
26
+ end
27
+
28
+ def tipo_de_evento
29
+ evento['evtExclusao/infoExclusao/tpEvento'].delete('-')
30
+ end
31
+
32
+ def excluir_arquivo_data_original
33
+ File.delete(criar_caminho_do_arquivo_data(extrair_nome_do_arquivo_data_original))
34
+ end
35
+
36
+ def extrair_nome_do_arquivo_data_original
37
+ de_recibo_para_nome_do_arquivo_data.delete(numero_de_recibo_do_evento_a_excluir)
38
+ end
39
+
40
+ def numero_de_recibo_do_evento_a_excluir
41
+ evento['evtExclusao/infoExclusao/nrRecEvt']
42
+ end
43
+ end
44
+ end
45
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teodoro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clavius Tales
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-08 00:00:00.000000000 Z
11
+ date: 2021-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: os
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rubyzip
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -161,13 +175,13 @@ files:
161
175
  - lib/teodoro.rb
162
176
  - lib/teodoro/arquivo_de_evento.rb
163
177
  - lib/teodoro/arquivo_de_evento_de_tabela.rb
178
+ - lib/teodoro/arquivo_de_evento_exceto_de_exclusao.rb
164
179
  - lib/teodoro/arquivo_de_evento_nao_periodico.rb
165
180
  - lib/teodoro/arquivo_de_origem.rb
166
181
  - lib/teodoro/arquivo_xml.rb
167
182
  - lib/teodoro/cnpj.rb
168
183
  - lib/teodoro/console.rb
169
184
  - lib/teodoro/empresa.rb
170
- - lib/teodoro/execucao.rb
171
185
  - lib/teodoro/leiaute_2_4_1.rb
172
186
  - lib/teodoro/leiaute_2_4_1/arquivo_s1000.rb
173
187
  - lib/teodoro/leiaute_2_4_1/arquivo_s1005.rb
@@ -185,6 +199,7 @@ files:
185
199
  - lib/teodoro/leiaute_2_4_1/arquivo_s2250.rb
186
200
  - lib/teodoro/leiaute_2_4_1/arquivo_s2300.rb
187
201
  - lib/teodoro/leiaute_2_4_1/arquivo_s2306.rb
202
+ - lib/teodoro/leiaute_2_4_1/arquivo_s3000.rb
188
203
  - lib/teodoro/xml.rb
189
204
  homepage:
190
205
  licenses: []
@@ -1,62 +0,0 @@
1
- require 'nokogiri'
2
- require 'zip'
3
-
4
- require_relative 'console'
5
- require_relative 'empresa'
6
-
7
- module Teodoro
8
- class Execucao
9
- private
10
-
11
- def initialize(origem:, destino:)
12
- @origem = origem
13
- @destino = destino
14
- end
15
-
16
- attr_reader :origem, :destino
17
-
18
- public
19
-
20
- def call
21
- executar
22
- rescue StandardError => e
23
- Console.print e.message, *e.backtrace, color: :red
24
- exit
25
- end
26
-
27
- private
28
-
29
- def executar
30
- validar_existencia_do_diretorio_de_origem
31
- validar_que_diretorio_de_origem_nao_esta_vazio
32
- validar_que_diretorio_de_destino_esta_vazio
33
-
34
- processar_empresas
35
- end
36
-
37
- def validar_existencia_do_diretorio_de_origem
38
- erro 'Diretório de origem não existe.' unless File.directory?(origem)
39
- end
40
-
41
- def validar_que_diretorio_de_origem_nao_esta_vazio
42
- erro 'Diretório de origem vazio.' if Dir.empty?(origem)
43
- end
44
-
45
- def validar_que_diretorio_de_destino_esta_vazio
46
- erro 'Diretório de destino deve estar vazio.' unless Dir.empty?(destino)
47
- end
48
-
49
- def erro(erro)
50
- puts erro
51
- exit
52
- end
53
-
54
- def processar_empresas
55
- empresas.each(&:processar)
56
- end
57
-
58
- def empresas
59
- Dir[File.join(origem, '*')].map { |caminho| Empresa.new(caminho: caminho, destino: destino) }
60
- end
61
- end
62
- end