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

Instance Method Summary collapse

Constructor Details

#initialize(report, sections:) ⇒ TriageRenderer

Returns a new instance of TriageRenderer.



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

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

Instance Method Details

#jsonObject



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

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

#textObject



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

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