Class: Reviewer::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/reviewer/report.rb,
lib/reviewer/report/formatter.rb

Overview

Collects results from multiple tool runs and provides serialization

Defined Under Namespace

Classes: Formatter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeReport

Returns a new instance of Report.



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

def initialize
  @results = []
  @duration = nil
end

Instance Attribute Details

#durationObject (readonly)

Returns the value of attribute duration.



9
10
11
# File 'lib/reviewer/report.rb', line 9

def duration
  @duration
end

#resultsObject (readonly)

Returns the value of attribute results.



9
10
11
# File 'lib/reviewer/report.rb', line 9

def results
  @results
end

Instance Method Details

#add(result) ⇒ Array<Runner::Result>

Adds a Runner::Result to the collection

Parameters:

Returns:



20
21
22
# File 'lib/reviewer/report.rb', line 20

def add(result)
  @results << result
end

#max_exit_statusInteger

Returns the highest exit status from executed results (excludes missing and skipped)

Returns:

  • (Integer)

    the maximum exit status, or 0 if empty



42
43
44
# File 'lib/reviewer/report.rb', line 42

def max_exit_status
  executed_results.map(&:exit_status).max || 0
end

#missing?Boolean

Whether any tools were missing

Returns:

  • (Boolean)

    true if any results are missing



56
57
58
# File 'lib/reviewer/report.rb', line 56

def missing?
  missing_results.any?
end

#missing_resultsArray<Runner::Result>

Returns results for tools whose executables were not found

Returns:



49
50
51
# File 'lib/reviewer/report.rb', line 49

def missing_results
  results.select(&:missing?)
end

#missing_toolsArray<Runner::Result>

Returns data for missing tools (name and key)

Returns:



63
64
65
# File 'lib/reviewer/report.rb', line 63

def missing_tools
  missing_results
end

#record_duration(seconds) ⇒ Float

Records the total duration for all tool runs

Parameters:

  • seconds (Float)

    the total elapsed time in seconds

Returns:

  • (Float)

    the recorded duration



28
29
30
# File 'lib/reviewer/report.rb', line 28

def record_duration(seconds)
  @duration = seconds
end

#success?Boolean

Whether all executed tools in the report succeeded (excludes missing and skipped)

Returns:

  • (Boolean)

    true if all executed results are successful



35
36
37
# File 'lib/reviewer/report.rb', line 35

def success?
  executed_results.all?(&:success?)
end

#to_hHash

Converts the report to a hash suitable for serialization

Returns:

  • (Hash)

    structured hash with summary and tool results



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/reviewer/report.rb', line 70

def to_h
  {
    success: success?,
    summary: {
      total: results.size,
      passed: results.count(&:success?),
      failed: results.count { |result| !result.success? && !result.missing? },
      missing: missing_results.size,
      duration: duration
    },
    tools: results.map(&:to_h)
  }
end

#to_json(*_args) ⇒ String

Converts the report to formatted JSON

Returns:

  • (String)

    JSON representation of the report



87
88
89
# File 'lib/reviewer/report.rb', line 87

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