Class: Necropsy::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/necropsy/reporter.rb

Constant Summary collapse

FORMATS =
%i[human json yaml yml sarif github annotations].freeze
DEFAULT_MIN_CONFIDENCE =
:medium

Instance Method Summary collapse

Constructor Details

#initialize(report) ⇒ Reporter

Returns a new instance of Reporter.



8
9
10
# File 'lib/necropsy/reporter.rb', line 8

def initialize(report)
  @report = report
end

Instance Method Details

#render(format: :human, min_confidence: DEFAULT_MIN_CONFIDENCE, include_graph: false) ⇒ Object

Raises:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/necropsy/reporter.rb', line 12

def render(format: :human, min_confidence: DEFAULT_MIN_CONFIDENCE, include_graph: false)
  normalized_format = format.to_sym
  raise Error, "Unknown report format: #{format}" unless FORMATS.include?(normalized_format)

  case normalized_format
  when :json
    report.to_json(include_graph: include_graph)
  when :sarif
    render_sarif(min_confidence)
  when :github, :annotations
    render_github_annotations(min_confidence)
  when :yaml, :yml
    report.to_yaml(include_graph: include_graph)
  when :human
    render_human(min_confidence)
  end
end