Class: Rigor::CLI::TypeOfRenderer

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

Overview

Renders a ‘TypeOfCommand::Result` as either human-readable text or a machine-readable JSON document.

The renderer is a separate concern from the command itself so that future output formats (sexp, lsp-style hover payloads, color decoration) can plug in without disturbing argument parsing or the inference call site.

Instance Method Summary collapse

Constructor Details

#initialize(out:) ⇒ TypeOfRenderer

Returns a new instance of TypeOfRenderer.



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

def initialize(out:)
  @out = out
end

Instance Method Details

#render(result, format:) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/rigor/cli/type_of_renderer.rb', line 19

def render(result, format:)
  case format
  when "text" then render_text(result)
  when "json" then render_json(result)
  else
    raise OptionParser::InvalidArgument, "unsupported format: #{format}"
  end
end