Class: DuperVisor::Renderer
- Inherits:
-
Object
- Object
- DuperVisor::Renderer
- Includes:
- Formats::Accessors
- Defined in:
- lib/dupervisor/renderer.rb
Instance Attribute Summary collapse
-
#content_hash ⇒ Object
Returns the value of attribute content_hash.
-
#output ⇒ Object
Returns the value of attribute output.
-
#rendered_content ⇒ Object
Returns the value of attribute rendered_content.
Instance Method Summary collapse
-
#initialize(content_hash, output_stream = nil) ⇒ Renderer
constructor
A new instance of Renderer.
- #render(format) ⇒ Object
Methods included from Formats::Accessors
Constructor Details
#initialize(content_hash, output_stream = nil) ⇒ Renderer
Returns a new instance of Renderer.
9 10 11 12 13 |
# File 'lib/dupervisor/renderer.rb', line 9 def initialize(content_hash, output_stream = nil) raise ArgumentError.new('Invalid arguments - expecting a stream and a hash') unless content_hash.is_a?(Hash) self.output = output_stream self.content_hash = content_hash end |
Instance Attribute Details
#content_hash ⇒ Object
Returns the value of attribute content_hash.
7 8 9 |
# File 'lib/dupervisor/renderer.rb', line 7 def content_hash @content_hash end |
#output ⇒ Object
Returns the value of attribute output.
7 8 9 |
# File 'lib/dupervisor/renderer.rb', line 7 def output @output end |
#rendered_content ⇒ Object
Returns the value of attribute rendered_content.
7 8 9 |
# File 'lib/dupervisor/renderer.rb', line 7 def rendered_content @rendered_content end |
Instance Method Details
#render(format) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/dupervisor/renderer.rb', line 15 def render(format) self.rendered_content = self.formats[format].to.call(content_hash) if output.respond_to?(:puts) output.puts rendered_content output.close if output.respond_to?(:close) && output != STDOUT end rendered_content end |