class Occi::Core::Renderers::Text::Base

Implements methods common to all text-based renderers. This class is not meant to be used directly, only as a parent to other type-specific rendering classes.

@attr object [Object] instance to be rendered @attr options [Hash] additional rendering options

@author Boris Parak <parak@cesnet.cz

Constants

DELEGATED

Shortcuts to interesting object attributes, always prefixed with `object_`

RENDER_SAFE

Ruby 2.3 compatibility, with `$SAFE` changes

Attributes

object[RW]
options[RW]

Public Class Methods

new(object, options) click to toggle source

Constructs a renderer instance for the given object.

@param object [Object] instance to be rendered @param options [Hash] additional options

# File lib/occi/core/renderers/text/base.rb, line 30
def initialize(object, options)
  @object = object
  @options = options
end
render_safe() click to toggle source

Returns an acceptable value for the $SAFE env variable that should be enforced when evaluating templates.

@return [Integer] SAFE level

# File lib/occi/core/renderers/text/base.rb, line 64
def render_safe
  RENDER_SAFE
end

Public Instance Methods

render() click to toggle source

Renders the given object to `text`.

@return [String] object rendering as plain text @return [Hash] object rendering as hash

# File lib/occi/core/renderers/text/base.rb, line 39
def render
  case options[:format]
  when 'text', 'text_plain'
    render_plain
  when 'headers', 'text_occi'
    render_headers
  else
    raise Occi::Core::Errors::RenderingError,
          "Rendering to #{options[:format]} is not supported"
  end
end
render_safe() click to toggle source

Returns an acceptable value for the $SAFE env variable that should be enforced when evaluating templates.

@return [Integer] SAFE level

# File lib/occi/core/renderers/text/base.rb, line 55
def render_safe
  RENDER_SAFE
end

Protected Instance Methods

render_headers() click to toggle source

Renders `object` into text for headers and returns the result as `Hash`.

@return [Hash] textual representation of Object for headers

# File lib/occi/core/renderers/text/base.rb, line 81
def render_headers; end
render_plain() click to toggle source

Renders `object` into plain text and returns the result as `String`.

@return [String] textual representation of Object

# File lib/occi/core/renderers/text/base.rb, line 75
def render_plain; end