Class: CodeHunter::Renderer

Inherits:
Object
  • Object
show all
Extended by:
MethodLogger
Defined in:
lib/code_hunter/renderer.rb

Overview

Render warnings to string with the specified format. As its format, AVAILABLE_FORMATS are available (“yaml” is default).

Constant Summary collapse

AVAILABLE_FORMATS =
%w[json yaml]

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MethodLogger

log

Constructor Details

#initialize(warnings, options = {}) ⇒ Renderer

Returns a new instance of Renderer.



16
17
18
19
# File 'lib/code_hunter/renderer.rb', line 16

def initialize(warnings, options = {})
  @warnings = warnings
  @format   = options[:format] || "yaml"
end

Class Method Details

.render(*args) ⇒ Object



12
13
14
# File 'lib/code_hunter/renderer.rb', line 12

def self.render(*args)
  new(*args).render
end

Instance Method Details

#renderObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/code_hunter/renderer.rb', line 21

def render
  case format
  when "yaml"
    @warnings.to_yaml
  when "json"
    JSON.unparse(@warnings)
  else
    raise ArgumentError, "format #{format} is not available. Use #{AVAILABLE_FORMATS}"
  end
end