Class: Occi::Core::Mixin

Inherits:
Category show all
Defined in:
lib/occi/core/mixin.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 = 'mixin', title = nil, attributes = Occi::Core::AttributeProperties.new, related = Occi::Core::Related.new, actions = Occi::Core::Actions.new, location = '') ⇒ Mixin


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

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

  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 = '/mixins/' + term + '/' : @location = location
end

Instance Attribute Details

#actionsObject

Returns the value of attribute actions


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

def actions
  @actions
end

#entitiesObject

Returns the value of attribute entities


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

def entities
  @entities
end

#locationObject

Returns the value of attribute location


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

def location
  @location
end

Returns the value of attribute related


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

def related
  @related
end

Instance Method Details

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


34
35
36
37
38
39
40
41
# File 'lib/occi/core/mixin.rb', line 34

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

#to_stringString


44
45
46
47
48
49
50
51
# File 'lib/occi/core/mixin.rb', line 44

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