Class: ConservationGuardian::Report

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(budget, profiler, findings) ⇒ Report

Returns a new instance of Report.



7
8
9
10
11
# File 'lib/conservation_guardian/report.rb', line 7

def initialize(budget, profiler, findings)
  @budget   = budget
  @profiler = profiler
  @findings = findings
end

Instance Attribute Details

#budgetObject (readonly)

Returns the value of attribute budget.



5
6
7
# File 'lib/conservation_guardian/report.rb', line 5

def budget
  @budget
end

#findingsObject (readonly)

Returns the value of attribute findings.



5
6
7
# File 'lib/conservation_guardian/report.rb', line 5

def findings
  @findings
end

#profilerObject (readonly)

Returns the value of attribute profiler.



5
6
7
# File 'lib/conservation_guardian/report.rb', line 5

def profiler
  @profiler
end

Instance Method Details

#summaryObject



22
23
24
25
26
27
28
29
30
# File 'lib/conservation_guardian/report.rb', line 22

def summary
  {
    total_samples: profiler.samples.size,
    total_findings: findings.size,
    over_budget: findings.count { |f| f[:type] == :over_budget },
    anomalies: findings.count { |f| f[:type] == :anomaly },
    categories_checked: budget.categories.size
  }
end

#to_hObject



13
14
15
16
17
18
19
20
# File 'lib/conservation_guardian/report.rb', line 13

def to_h
  {
    budget:   budget.to_h,
    stats:    profiler.all_stats,
    findings: findings,
    summary:  summary
  }
end

#to_sObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/conservation_guardian/report.rb', line 32

def to_s
  lines = []
  lines << "=== Conservation Guardian Report ==="
  lines << "Budget: #{budget.name}"
  lines << "Samples analyzed: #{summary[:total_samples]}"
  lines << "Findings: #{summary[:total_findings]} (#{summary[:over_budget]} over budget, #{summary[:anomalies]} anomalies)"
  lines << ""

  if findings.any?
    lines << "--- Findings ---"
    findings.each do |f|
      lines << "[#{f[:severity].upcase}] #{f[:message]}"
    end
  else
    lines << "✅ No waste detected. All clear!"
  end

  lines.join("\n")
end