Class: Occi::Core::Renderers::Text::Category

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

Overview

Implements routines required to render ‘Occi::Core::Category` and its subclasses to a text-based representation. Supports rendering to plain and header-like formats. Internally, the rendering itself is done via ERB templates.

Author:

Constant Summary collapse

CATEGORY_KEY_PLAIN =

Category key constants

'Category'.freeze
CATEGORY_KEY_HEADERS =
'X-OCCI-Category'.freeze

Constants inherited from Base

Base::DELEGATED, Base::RENDER_SAFE

Instance Attribute Summary

Attributes inherited from Base

#object, #options

Class Method Summary collapse

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

Class Method Details

.category_key_headersString

Returns word used to key all categories rendered to headers.

Returns:

  • (String)

    category key



61
62
63
# File 'lib/occi/core/renderers/text/category.rb', line 61

def category_key_headers
  CATEGORY_KEY_HEADERS
end

.category_key_plainString

Returns keyword used to prefix all categories rendered to plain text.

Returns:

  • (String)

    category keyword



54
55
56
# File 'lib/occi/core/renderers/text/category.rb', line 54

def category_key_plain
  CATEGORY_KEY_PLAIN
end

.templateString

Returns a static ERB template used to render ‘Category`-like instances to plain text.

Returns:

  • (String)

    ERB template



168
169
170
171
172
173
174
175
176
177
# File 'lib/occi/core/renderers/text/category.rb', line 168

def template
  '<%= obj_data[:term] %>; ' \
  'scheme="<%= obj_data[:schema] %>"; ' \
  'class="<%= obj_data[:subclass] %>"' \
  '<% if long? && obj_data[:title] %>; title="<%= obj_data[:title] %>"<% end %>' \
  '<% if long? && obj_data[:rel] %>; rel="<%= obj_data[:rel] %>"<% end %>' \
  '<% if long? && obj_data[:location] %>; location="<%= obj_data[:location] %>"<% end %>' \
  '<% if long? && obj_data[:attributes] %>; attributes="<%= obj_data[:attributes] %>"<% end %>' \
  '<% if long? && obj_data[:actions] %>; actions="<%= obj_data[:actions] %>"<% end %>'
end

Instance Method Details

#category_key_headersString

Returns word used to key all categories rendered to headers.

Returns:

  • (String)

    category key



46
47
48
# File 'lib/occi/core/renderers/text/category.rb', line 46

def category_key_headers
  CATEGORY_KEY_HEADERS
end

#category_key_plainString

Returns keyword used to prefix all categories rendered to plain text.

Returns:

  • (String)

    category keyword



39
40
41
# File 'lib/occi/core/renderers/text/category.rb', line 39

def category_key_plain
  CATEGORY_KEY_PLAIN
end

#render_headersHash

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

Returns:

  • (Hash)

    textual representation of Object for headers



31
32
33
34
# File 'lib/occi/core/renderers/text/category.rb', line 31

def render_headers
  obj_data = object_data
  { CATEGORY_KEY_HEADERS => [erb_render(obj_data)] }
end

#render_plainString

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

Returns:

  • (String)

    textual representation of Object



22
23
24
25
# File 'lib/occi/core/renderers/text/category.rb', line 22

def render_plain
  obj_data = object_data
  "#{CATEGORY_KEY_PLAIN}: #{erb_render(obj_data)}"
end