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, #mixins, #model

Instance Method Summary collapse

Methods inherited from Entity

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

Constructor Details

#initialize(kind = self.kind, mixins = [], attributes = { }, actions = [], rel = nil, target = nil, source = 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: nil)
  • target (String, Occi::Core::Entity) (defaults to: nil)
  • source (String, Occi::Core::Entity) (defaults to: nil)


25
26
27
28
29
30
31
32
33
# File 'lib/occi/core/link.rb', line 25

def initialize(kind=self.kind, mixins=[], attributes={ }, actions=[], rel=nil, target=nil, source=nil)
  super(kind, mixins, attributes, actions)
  if rel.kind_of? String
    scheme, term = rel.to_s.split('#')
    @rel         = Occi::Core::Category.get_class(scheme, term).kind if scheme && term
  end
  @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



48
49
50
# File 'lib/occi/core/link.rb', line 48

def source
  @source
end

#targetString

Returns target attribute of the link.

Returns:

  • (String)

    target attribute of the link



36
37
38
# File 'lib/occi/core/link.rb', line 36

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



67
68
69
70
71
72
73
# File 'lib/occi/core/link.rb', line 67

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:



60
61
62
63
# File 'lib/occi/core/link.rb', line 60

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



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/occi/core/link.rb', line 76

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
  string << ';'
  @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.to_s

  string
end

Returns text representation of link.

Returns:

  • (String)

    text representation of link



94
95
96
# File 'lib/occi/core/link.rb', line 94

def to_text_link
  'Link: ' + self.to_string
end