Class: Occi::Core::Category Abstract

Inherits:
Object
  • Object
show all
Extended by:
Helpers::IdentifierValidator, Helpers::YamlSummoner
Includes:
Helpers::ArgumentValidator, Helpers::AttributesAccessor, Helpers::Renderable, Yell::Loggable
Defined in:
lib/occi/core/category.rb

Overview

This class is abstract.

The base class itself is not renderable and should be used as an abstract starting point.

Implements the base class for all OCCI categories, including `Kind`, `Action`, and `Mixin`.

Author:

Direct Known Subclasses

Action, Kind, Mixin

Constant Summary

Constants included from Helpers::IdentifierValidator

Helpers::IdentifierValidator::PROHIBITED_SCHEMA_CHARS, Helpers::IdentifierValidator::REGEXP_TERM

Constants included from Helpers::Renderable

Helpers::Renderable::RENDERER_FACTORY_CLASS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::YamlSummoner

from_yaml, needs_dereferencing?

Methods included from Helpers::IdentifierValidator

prohibited_chars!, valid_identifier!, valid_identifier?, valid_schema!, valid_schema?, valid_term!, valid_term?, valid_uri!

Methods included from Helpers::AttributesAccessor

#[], #[]=

Methods included from Helpers::Renderable

extended, included, #render, #renderer_factory, renderer_factory, renderer_factory_class, #renderer_for

Constructor Details

#initialize(args = {}) ⇒ Category

Constructs an instance with the given category information. Both `term` and `schema` are mandatory arguments. `schema` must be terminated with '#'.

Examples:

Category.new term: 'gnr', schema: 'http://example.org/test#'

Parameters:

  • args (Hash) (defaults to: {})

    arguments with category information

Options Hash (args):

  • :term (String)

    category term

  • :schema (String)

    category schema, ending with '#'

  • :title (String) — default: nil

    category title

  • :attributes (Hash) — default: Hash

    category attributes


38
39
40
41
42
43
44
45
46
47
48
# File 'lib/occi/core/category.rb', line 38

def initialize(args = {})
  pre_initialize(args)
  default_args! args

  @term = args.fetch(:term)
  @schema = args.fetch(:schema)
  @title = args.fetch(:title)
  @attributes = args.fetch(:attributes)

  post_initialize(args)
end

Instance Attribute Details

#attributesHash

category attributes

Returns:

  • (Hash)

    the current value of attributes


16
17
18
# File 'lib/occi/core/category.rb', line 16

def attributes
  @attributes
end

#identifierString (readonly)

Returns a full category identifier constructed from `term` and `schema`.

Examples:

category.identifier  # => 'http://example.org/test#gnr'

Returns:

  • (String)

    category identifier


16
17
18
# File 'lib/occi/core/category.rb', line 16

def identifier
  @identifier
end

#schemaString

category schema, ending with '#'

Returns:

  • (String)

    the current value of schema


16
17
18
# File 'lib/occi/core/category.rb', line 16

def schema
  @schema
end

#termString

category term

Returns:

  • (String)

    the current value of term


16
17
18
# File 'lib/occi/core/category.rb', line 16

def term
  @term
end

#titleString

category title

Returns:

  • (String)

    the current value of title


16
17
18
# File 'lib/occi/core/category.rb', line 16

def title
  @title
end

Instance Method Details

#==(other) ⇒ Object

:nodoc:


94
95
96
97
# File 'lib/occi/core/category.rb', line 94

def ==(other)
  return false unless other && other.respond_to?(:identifier)
  identifier == other.identifier
end

#eql?(other) ⇒ Boolean

:nodoc:

Returns:


100
101
102
# File 'lib/occi/core/category.rb', line 100

def eql?(other)
  self == other
end

#hashObject

:nodoc:


105
106
107
# File 'lib/occi/core/category.rb', line 105

def hash
  identifier.hash
end

#to_sObject

:nodoc:


89
90
91
# File 'lib/occi/core/category.rb', line 89

def to_s
  identifier
end

#valid!Object

Performs internal validation of the category. Raises error depending on the result. Currently, only the category identifier is used in this process.

Examples:

category.valid!

Raises:


83
84
85
86
# File 'lib/occi/core/category.rb', line 83

def valid!
  # TODO: validate attribute definitions?
  self.class.valid_identifier! identifier
end

#valid?TrueClass, FalseClass

Performs internal validation of the category. Returns `true` or `false` depending on the result. Currently, only the category identifier is used in this process.

Examples:

category.valid?  # => true

Returns:


70
71
72
73
# File 'lib/occi/core/category.rb', line 70

def valid?
  # TODO: validate attribute definitions?
  self.class.valid_identifier? identifier
end