Class: Bddgenx::Tracer

Inherits:
Object
  • Object
show all
Defined in:
lib/bddgenx/tracer.rb

Class Method Summary collapse

Class Method Details

.adicionar_entrada(historia, nome_arquivo_feature) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/bddgenx/tracer.rb', line 6

def self.adicionar_entrada(historia, nome_arquivo_feature)
  FileUtils.mkdir_p('reports/output')
  arquivo_csv = 'reports/output/rastreabilidade.csv'

  cabecalho = ['Funcionalidade', 'Tipo', 'Tag', 'Cenário', 'Passo', 'Origem']

  linhas = []

  historia[:grupos].each_with_index do |grupo, idx|
    tipo = grupo[:tipo]
    tag  = grupo[:tag]
    passos = grupo[:passos]

    nome_funcionalidade = historia[:quero].gsub(/^Quero\s*/, '').strip
    nome_cenario = "Cenário #{idx + 1}"

    passos.each do |passo|
      linhas << [
        nome_funcionalidade,
        tipo,
        tag || '-',
        nome_cenario,
        passo,
        File.basename(nome_arquivo_feature)
      ]
    end
  end

  escrever_csv(arquivo_csv, cabecalho, linhas)
end

.escrever_csv(caminho, cabecalho, linhas) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/bddgenx/tracer.rb', line 37

def self.escrever_csv(caminho, cabecalho, linhas)
  novo_arquivo = !File.exist?(caminho)

  CSV.open(caminho, 'a+', col_sep: ';', force_quotes: true) do |csv|
    csv << cabecalho if novo_arquivo
    linhas.each { |linha| csv << linha }
  end
end