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, #related_to?, #to_header, #to_s, #to_string_short, #to_text, #type_identifier

Methods included from Helpers::Inspect

#inspect

Constructor Details

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


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::AttributeProperties.new,
    related=Occi::Core::Related.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

#parentObject

Returns the value of attribute parent


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

def parent
  @parent
end

Instance Method Details

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


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


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