Class: Necropsy::Report

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root:, graph:, findings:) ⇒ Report

Returns a new instance of Report.



10
11
12
13
14
# File 'lib/necropsy/report.rb', line 10

def initialize(root:, graph:, findings:)
  @root = root
  @graph = graph
  @findings = findings
end

Instance Attribute Details

#findingsObject (readonly)

Returns the value of attribute findings.



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

def findings
  @findings
end

#graphObject (readonly)

Returns the value of attribute graph.



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

def graph
  @graph
end

#rootObject (readonly)

Returns the value of attribute root.



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

def root
  @root
end

Instance Method Details

#dead_methods(min_confidence: :low) ⇒ Object



16
17
18
# File 'lib/necropsy/report.rb', line 16

def dead_methods(min_confidence: :low)
  findings.select { |finding| finding.at_least?(min_confidence) }
end

#summaryObject



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/necropsy/report.rb', line 37

def summary
  grouped = findings.group_by(&:classification)
  {
    'nodes' => graph.nodes.length,
    'edges' => graph.edges.length,
    'entry_points' => graph.entry_points.length,
    'findings' => findings.length,
    'unreachable' => grouped.fetch(:unreachable, []).length,
    'unused' => grouped.fetch(:unused, []).length,
    'test_only_reachable' => grouped.fetch(:test_only_reachable, []).length
  }
end

#to_hObject



20
21
22
23
24
25
26
27
# File 'lib/necropsy/report.rb', line 20

def to_h
  {
    'root' => root,
    'summary' => summary,
    'findings' => findings.map(&:to_h),
    'graph' => graph.to_h
  }
end

#to_jsonObject



29
30
31
# File 'lib/necropsy/report.rb', line 29

def to_json(*)
  JSON.pretty_generate(to_h, *)
end

#to_yamlObject



33
34
35
# File 'lib/necropsy/report.rb', line 33

def to_yaml
  to_h.to_yaml
end