Class: Occi::Core::Link

Inherits:
Entity
  • Object
show all
Defined in:
lib/occi/core/link.rb

Instance Attribute Summary collapse

Attributes inherited from Entity

#actions, #attributes, #id, #kind, #location, #mixins, #model

Instance Method Summary collapse

Methods inherited from Entity

check, new, #title, #title=, #to_header, #to_s, #to_text, type_identifier

Methods included from Helpers::Inspect

#inspect

Constructor Details

#initialize(kind = self.kind, mixins = [], attributes = {}, actions = [], rel = Occi::Core::Link.type_identifier, target = nil, source = nil, location = nil) ⇒ Link

Returns a new instance of Link

Parameters:

  • kind (String) (defaults to: self.kind)
  • mixins (String) (defaults to: [])
  • attributes (Occi::Core::Attributes) (defaults to: {})
  • actions (Array) (defaults to: [])
  • rel (String) (defaults to: Occi::Core::Link.type_identifier)
  • target (String, Occi::Core::Entity) (defaults to: nil)
  • source (String, Occi::Core::Entity) (defaults to: nil)

24
25
26
27
28
29
30
# File 'lib/occi/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::Category.get_class(scheme, term).kind if scheme && term
  @source = source if source
  @target = target
end

Instance Attribute Details

#relObject

Returns the value of attribute rel


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

def rel
  @rel
end

#sourceString

Returns source attribute of the link

Returns:

  • (String)

    source attribute of the link


45
46
47
# File 'lib/occi/core/link.rb', line 45

def source
  @source
end

#targetString

Returns target attribute of the link

Returns:

  • (String)

    target attribute of the link


33
34
35
# File 'lib/occi/core/link.rb', line 33

def target
  @target
end

Instance Method Details

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

Returns json representation

Parameters:

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

Returns:

  • (Hashie::Mash)

    json representation


64
65
66
67
68
69
70
# File 'lib/occi/core/link.rb', line 64

def as_json(options={})
  link = super
  link.rel = @rel.to_s if @rel
  link.source = self.source.to_s if self.source.to_s
  link.target = self.target.to_s if self.target
  link
end

#checkObject

Parameters:


57
58
59
60
# File 'lib/occi/core/link.rb', line 57

def check
  raise "rel must be provided" unless @rel
  super
end

#to_stringString

Returns text representation of link reference

Returns:

  • (String)

    text representation of link reference


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/occi/core/link.rb', line 73

def to_string
  string = '<' + self.target.to_s + '>'
  string << ';rel=' + @rel.to_s.inspect
  string << ';self=' + self.location.inspect if self.location
  categories = [@kind] + @mixins.join(',').split(',')
  string << ';category=' + categories.join(' ').inspect
  @attributes.combine.each_pair do |name, value|
    value = value.inspect
    string << ';' + name + '=' + value
  end
  string << ';occi.core.target=' + self.target.to_s.inspect
  string << ';occi.core.source=' + self.source.to_s.inspect if self.source

  string
end

Returns text representation of link

Returns:

  • (String)

    text representation of link


90
91
92
# File 'lib/occi/core/link.rb', line 90

def to_text_link
  'Link: ' + self.to_string
end