Class: Rigor::CLI::TriageRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/rigor/cli/triage_renderer.rb

Overview

ADR-23 — renders a Triage::Report as the ‘rigor triage` text report or as `–format json`.

Constant Summary collapse

BAR_WIDTH =
24
SELECTOR_ROWS =

text-output cap; ‘–format json` carries the full list

15

Instance Method Summary collapse

Constructor Details

#initialize(report, sections:) ⇒ TriageRenderer

Returns a new instance of TriageRenderer.



15
16
17
18
# File 'lib/rigor/cli/triage_renderer.rb', line 15

def initialize(report, sections:)
  @report = report
  @sections = sections # subset of %i[distribution selectors hotspots hints]
end

Instance Method Details

#jsonObject



20
21
22
# File 'lib/rigor/cli/triage_renderer.rb', line 20

def json
  JSON.pretty_generate(Triage.report_to_h(@report))
end

#textObject



24
25
26
27
28
29
30
31
# File 'lib/rigor/cli/triage_renderer.rb', line 24

def text
  blocks = []
  blocks << distribution_block if @sections.include?(:distribution)
  blocks << selectors_block    if @sections.include?(:selectors)
  blocks << hotspots_block     if @sections.include?(:hotspots)
  blocks << hints_block        if @sections.include?(:hints)
  "#{blocks.join("\n\n")}\n"
end