class Occi::Core::Link

Attributes

rel[RW]
source[RW]
target[RW]

Public Class Methods

new(kind=self.kind, mixins=[], attributes={}, actions=[], rel=Occi::Core::Link.type_identifier, target=nil, source=nil, location=nil) click to toggle source

@param [String] kind @param [String] mixins @param [Occi::Core::Attributes] attributes @param [Array] actions @param [String] rel @param [String,Occi::Core::Entity] target @param [String,Occi::Core::Entity] source

Calls superclass method Occi::Core::Entity.new
# File lib/occi4/core/link.rb, line 24
def initialize(kind=self.kind, mixins=[], attributes={}, actions=[], rel=Occi::Core::Link.type_identifier, target=nil, source=nil, location=nil)
  super(kind, mixins, attributes, actions, location)
  scheme, term = rel.to_s.split('#')
  @rel = Occi::Core::Kind.get_class(scheme, term).kind if scheme && term
  @source = source if source
  @target = target
end

Public Instance Methods

as_json(options={}) click to toggle source

@param [Hash] options @return [Hashie::Mash] json representation

Calls superclass method Occi::Core::Entity#as_json
# File lib/occi4/core/link.rb, line 66
def as_json(options={})
  link = super
  link.rel = @rel.to_s if @rel
  link.source = self.source.to_s unless self.source.to_s.blank?
  link.target = self.target.to_s if self.target
  link
end
check(set_defaults = false) click to toggle source

Runs check on attributes

Calls superclass method Occi::Core::Entity#check
# File lib/occi4/core/link.rb, line 59
def check(set_defaults = false)
  raise ArgumentError, "Cannot run check on #{self.to_s.inspect} kind #{self.kind.to_s.inspect} without relation (the rel attribute) set!" unless @rel
  super
end
source=(source) click to toggle source

set source attribute of link @param [String] source

# File lib/occi4/core/link.rb, line 53
def source=(source)
  self.attributes['occi.core.source'] = source.to_s
  @source = source.to_s
end
target=(target) click to toggle source

set target attribute of link @param [String] target

# File lib/occi4/core/link.rb, line 40
def target=(target)
  self.attributes['occi.core.target'] = target.to_s
  @target = target.to_s
end
to_string() click to toggle source

@return [String] text representation of link reference

# File lib/occi4/core/link.rb, line 75
def to_string
  string = "<#{self.target.to_s}>"
  string << ";rel=#{@rel.to_s.inspect}"
  string << ";self=#{self.location.inspect}" if self.location

  categories = [@kind.type_identifier].concat(@mixins.to_a.collect { |m| m.type_identifier })
  string << ";category=#{categories.join(' ').inspect}"

  string << @attributes.to_string

  string
end