Class: Attractor::ConsoleReporter::CSVFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/attractor/reporters/console_reporter.rb

Instance Method Summary collapse

Instance Method Details

#call(calculators) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/attractor/reporters/console_reporter.rb', line 30

def call(calculators)
  require "csv"

  result = CSV.generate do |csv|
    csv << %w[file_path score complexity churn type refactor]

    calculators.each do |calc|
      type = calc.last.type
      values = calc.last.calculate
      suggester = Suggester.new(values)
      to_be_refactored = suggester.suggest.map(&:file_path)

      values.each do |value|
        csv << [value.file_path, value.score, value.complexity, value.churn, type, to_be_refactored.include?(value.file_path)]
      end
    end
  end

  puts result
end