Class: Insika::ToolUsageReport::Report

Inherits:
Data
  • Object
show all
Defined in:
lib/insika/tool_usage_report.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#agentsObject (readonly)

Returns the value of attribute agents

Returns:

  • (Object)

    the current value of agents



36
37
38
# File 'lib/insika/tool_usage_report.rb', line 36

def agents
  @agents
end

#daysObject (readonly)

Returns the value of attribute days

Returns:

  • (Object)

    the current value of days



36
37
38
# File 'lib/insika/tool_usage_report.rb', line 36

def days
  @days
end

#generated_atObject (readonly)

Returns the value of attribute generated_at

Returns:

  • (Object)

    the current value of generated_at



36
37
38
# File 'lib/insika/tool_usage_report.rb', line 36

def generated_at
  @generated_at
end

#rowsObject (readonly)

Returns the value of attribute rows

Returns:

  • (Object)

    the current value of rows



36
37
38
# File 'lib/insika/tool_usage_report.rb', line 36

def rows
  @rows
end

Instance Method Details

#to_hObject



37
38
39
40
# File 'lib/insika/tool_usage_report.rb', line 37

def to_h
  { "generated_at" => generated_at, "days" => days, "agents" => agents,
    "rows" => rows.map(&:to_h) }
end

#to_sObject

Human report, grouped by agent. Silent agents still print their header — "nothing flagged" is a result, not an omission.



44
45
46
47
48
49
50
51
52
# File 'lib/insika/tool_usage_report.rb', line 44

def to_s
  lines = ["tool usage — last #{days} day(s), generated #{generated_at}"]
  agents.each do |agent|
    mine = rows.select { |r| r.agent == agent }
    lines << "" << "#{agent}: #{mine.empty? ? 'nothing flagged' : "#{mine.length} finding(s)"}"
    mine.each { |r| lines << format("  %-13s %s — %s", r.kind, r.tool, r.detail) }
  end
  lines.join("\n")
end