Class: CodeKeeper::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/code_keeper/formatter.rb

Overview

Format a result and make it human-readable.

Class Method Summary collapse

Class Method Details

.format(result) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/code_keeper/formatter.rb', line 9

def format(result)
  return result.scores.to_json if CodeKeeper.config.format == :json

  # csv is supported besides json
  csv_array = []
  result.scores.each_key do |metric|
    result.scores[metric].each { |k, v| csv_array << [metric, k, v] }
  end

  headers = %w[metric file score]
  CSV.generate(headers: true) do |csv|
    csv << headers
    csv_array.each { |array| csv << array }
  end
end