Class: RosettAi::Comply::Reporter

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

Overview

Formats compliance check results for display.

TTY-aware: coloured table when interactive, plain text when piped. Supports JSON output mode for CI integration.

Author:

  • hugo

  • claude

Instance Method Summary collapse

Constructor Details

#initialize(results:, format: 'table', output: $stdout) ⇒ Reporter

Returns a new instance of Reporter.

Parameters:

  • results (Array<Hash>)

    check results from Runner

  • format (String) (defaults to: 'table')

    output format ('table' or 'json')

  • output (IO) (defaults to: $stdout)

    output stream (default: $stdout)



23
24
25
26
27
# File 'lib/rosett_ai/comply/reporter.rb', line 23

def initialize(results:, format: 'table', output: $stdout)
  @results = results
  @format = format
  @output = output
end

Instance Method Details

#exit_codeInteger

Computes exit code from results.

Returns:

  • (Integer)

    0 = all pass, 1 = warnings only, 2 = any failure



42
43
44
45
46
47
# File 'lib/rosett_ai/comply/reporter.rb', line 42

def exit_code
  return 2 if @results.any? { |r| r[:status] == 'fail' }
  return 1 if @results.any? { |r| r[:status] == 'warn' }

  0
end

#report

This method returns an undefined value.

Renders the compliance report.



32
33
34
35
36
37
# File 'lib/rosett_ai/comply/reporter.rb', line 32

def report
  case @format
  when 'json' then report_json
  else report_table
  end
end