Class: Occi::Core::Renderers::Text::Collection

Inherits:
Model
  • Object
show all
Defined in:
lib/occi/core/renderers/text/collection.rb

Overview

Implements methods needed to render collection instances to text-based renderings. This class (its instances) is usually called directly from the “outside”. It utilizes `Model` from this module to render kinds, actions, and mixins. As well as `Resource`, `Link`, and `ActionInstance`.

Author:

Constant Summary

Constants inherited from Base

Base::DELEGATED, Base::RENDER_SAFE

Instance Attribute Summary

Attributes inherited from Base

#object, #options

Instance Method Summary collapse

Methods inherited from Base

#initialize, #render, #render_safe, render_safe

Constructor Details

This class inherits a constructor from Occi::Core::Renderers::Text::Base

Instance Method Details

#render_headersHash

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


35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/occi/core/renderers/text/collection.rb', line 35

def render_headers
  return {} if object_empty? || object.only_categories?

  if ent_no_ai?
    prepare_instances 'entities'
  elsif ai_no_ent?
    prepare_instances 'action_instances'
  else
    raise Occi::Core::Errors::RenderingError,
          'Cannot render mixed collection to text headers'
  end
end

#render_plainString

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


18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/occi/core/renderers/text/collection.rb', line 18

def render_plain
  return '' if object_empty? || object.only_categories?

  if ent_no_ai?
    prepare_instances 'entities'
  elsif ai_no_ent?
    prepare_instances 'action_instances'
  else
    raise Occi::Core::Errors::RenderingError,
          'Cannot render mixed collection to plain text'
  end
end