Class: Occi::Core::Kind

Inherits:
Category show all
Defined in:
lib/occi/core/kind.rb

Instance Attribute Summary collapse

Attributes inherited from Category

#attributes, #model, #scheme, #term, #title

Instance Method Summary collapse

Methods inherited from Category

categories, get_class, #inspect, #related_to?, #to_header, #to_s, #to_string_short, #to_text, #type_identifier

Constructor Details

#initialize(scheme = 'http://schemas.ogf.org/occi/core#', term = 'kind', title = nil, attributes = Occi::Core::Attributes.new, related = Occi::Core::Categories.new, actions = Occi::Core::Actions.new, location = nil) ⇒ Kind

Returns a new instance of Kind.

Parameters:

  • scheme (String) (defaults to: 'http://schemas.ogf.org/occi/core#')
  • term (String) (defaults to: 'kind')
  • title (String) (defaults to: nil)
  • attributes (Hash) (defaults to: Occi::Core::Attributes.new)
  • related (Array) (defaults to: Occi::Core::Categories.new)
  • actions (Array) (defaults to: Occi::Core::Actions.new)


13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/occi/core/kind.rb', line 13

def initialize(scheme='http://schemas.ogf.org/occi/core#',
    term='kind',
    title=nil,
    attributes=Occi::Core::Attributes.new,
    related=Occi::Core::Categories.new,
    actions=Occi::Core::Actions.new,
    location=nil)
  super(scheme, term, title, attributes)
  @related  = Occi::Core::Related.new(related)
  @actions  = Occi::Core::Actions.new(actions)
  @entities = Occi::Core::Entities.new
  location.blank? ? @location = '/' + term + '/' : @location = location
end

Instance Attribute Details

#actionsObject

Returns the value of attribute actions.



5
6
7
# File 'lib/occi/core/kind.rb', line 5

def actions
  @actions
end

#entitiesObject

Returns the value of attribute entities.



5
6
7
# File 'lib/occi/core/kind.rb', line 5

def entities
  @entities
end

#locationObject

Returns the value of attribute location.



5
6
7
# File 'lib/occi/core/kind.rb', line 5

def location
  @location
end

Returns the value of attribute related.



5
6
7
# File 'lib/occi/core/kind.rb', line 5

def related
  @related
end

Instance Method Details

#as_json(options = { }) ⇒ Hashie::Mash

Returns json representation.

Parameters:

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

Returns:

  • (Hashie::Mash)

    json representation



37
38
39
40
41
42
43
44
# File 'lib/occi/core/kind.rb', line 37

def as_json(options={ })
  kind = Hashie::Mash.new
  kind.related = @related.join(' ').split(' ') if @related.any?
  kind.actions = @actions.join(' ').split(' ') if @actions.any?
  kind.location = @location if @location
  kind.merge! super
  kind
end

#entity_typeObject



27
28
29
# File 'lib/occi/core/kind.rb', line 27

def entity_type
  self.class.get_class @scheme, @term, @related
end

#to_stringString

Returns string representation of the kind.

Returns:

  • (String)

    string representation of the kind



47
48
49
50
51
52
53
54
# File 'lib/occi/core/kind.rb', line 47

def to_string
  string = super
  string << ';rel=' + @related.join(' ').inspect if @related.any?
  string << ';location=' + self.location.inspect
  string << ';attributes=' + @attributes.combine.keys.join(' ').inspect if @attributes.any?
  string << ';actions=' + @actions.join(' ').inspect if @actions.any?
  string
end