Class: Bddgenx::Runner
- Inherits:
-
Object
- Object
- Bddgenx::Runner
- Defined in:
- lib/bddgenx/runner.rb
Class Method Summary collapse
-
.choose_files(input_dir) ⇒ Object
Retorna arquivos a processar: usa ARGV ou prompt interativo.
-
.choose_input(input_dir) ⇒ Object
Prompt interativo único.
- .execute ⇒ Object
-
.selecionar_arquivos_txt(input_dir) ⇒ Object
Seleciona arquivos .txt via argumentos.
Class Method Details
.choose_files(input_dir) ⇒ Object
Retorna arquivos a processar: usa ARGV ou prompt interativo
14 15 16 17 18 19 20 |
# File 'lib/bddgenx/runner.rb', line 14 def self.choose_files(input_dir) if ARGV.any? selecionar_arquivos_txt(input_dir) else choose_input(input_dir) end end |
.choose_input(input_dir) ⇒ Object
Prompt interativo único
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/bddgenx/runner.rb', line 36 def self.choose_input(input_dir) files = Dir.glob(File.join(input_dir, '*.txt')) if files.empty? warn "❌ Não há arquivos .txt no diretório #{input_dir}" exit 1 end puts "Selecione o arquivo de história para processar:" files.each_with_index { |f,i| puts "#{i+1}. #{File.basename(f)}" } print "Digite o número correspondente (ou ENTER para todos): " choice = STDIN.gets.chomp return files if choice.empty? idx = choice.to_i - 1 unless idx.between?(0, files.size-1) warn "❌ Escolha inválida."; exit 1 end [files[idx]] end |
.execute ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/bddgenx/runner.rb', line 55 def self.execute input_dir = 'input' Dir.mkdir(input_dir) unless Dir.exist?(input_dir) arquivos = choose_files(input_dir) if arquivos.empty? warn "❌ Nenhum arquivo de história para processar."; exit 1 end total = features = steps = ignored = 0 skipped_steps = [] generated_pdfs = [] skipped_pdfs = [] arquivos.each do |arquivo| total += 1 puts "\n🔍 Processando: #{arquivo}" historia = Parser.ler_historia(arquivo) unless Validator.validar(historia) ignored += 1; puts "❌ Arquivo inválido: #{arquivo}"; next end # Gera feature feature_path, feature_content = Generator.gerar_feature(historia) Backup.salvar_versao_antiga(feature_path) features += 1 if Generator.salvar_feature(feature_path, feature_content) # Gera steps if StepsGenerator.gerar_passos(feature_path) steps += 1 else skipped_steps << feature_path end # Exporta PDFs FileUtils.mkdir_p('reports') results = PDFExporter.exportar_todos(only_new: true) generated_pdfs.concat(results[:generated]) skipped_pdfs.concat(results[:skipped]) end # Resumo final puts "\n✅ Processamento concluído" puts "- Total de histórias: #{total}" puts "- Features geradas: #{features}" puts "- Steps gerados: #{steps}" puts "- Steps ignorados: #{skipped_steps.size}" puts "- PDFs gerados: #{generated_pdfs.size}" puts "- PDFs já existentes: #{skipped_pdfs.size}" puts "- Arquivos ignorados: #{ignored}" end |
.selecionar_arquivos_txt(input_dir) ⇒ Object
Seleciona arquivos .txt via argumentos
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/bddgenx/runner.rb', line 23 def self.selecionar_arquivos_txt(input_dir) ARGV.map do |arg| nome = arg.end_with?('.txt') ? arg : "#{arg}.txt" path = File.join(input_dir, nome) unless File.exist?(path) warn "⚠️ Arquivo não encontrado: #{path}" next end path end.compact end |