Class: CodeHunter::Renderer
- Inherits:
-
Object
- Object
- CodeHunter::Renderer
- 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
-
#initialize(warnings, options = {}) ⇒ Renderer
constructor
A new instance of Renderer.
- #render ⇒ Object
Methods included from MethodLogger
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, = {}) @warnings = warnings @format = [: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
#render ⇒ Object
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 |