Class: SimcovAiFormatter::Formatter

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

Overview

Transforms SimpleCov’s coverage hash into the AI-friendly Hash shape.

Input: { “<abs_path>” => { “lines” => [null|0|N, …], “branches” => …? } } Output: see README for the full schema.

Instance Method Summary collapse

Constructor Details

#initialize(coverage:, suite:, root:, suites_merged: nil, with_source: false, context: 2, source_reader: nil) ⇒ Formatter

Returns a new instance of Formatter.



9
10
11
12
13
14
15
16
17
# File 'lib/simcov_ai_formatter/formatter.rb', line 9

def initialize(coverage:, suite:, root:, suites_merged: nil, with_source: false, context: 2, source_reader: nil)
  @coverage = coverage
  @suite = suite
  @suites_merged = suites_merged
  @root = Pathname.new(root).expand_path
  @with_source = with_source
  @context = context
  @source_reader = source_reader
end

Instance Method Details

#callObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/simcov_ai_formatter/formatter.rb', line 19

def call
  files = build_files
  project_summary = aggregate_summary(files)

  result = {
    "schema_version" => 1,
    "suite" => @suite,
    "root" => @root.to_s,
    "summary" => project_summary,
    "files" => files
  }
  if @suites_merged && @suites_merged.size > 1
    result["suites_merged"] = @suites_merged
  end
  result
end