Class: Occi::Core::Link
Direct Known Subclasses
Infrastructure::Networkinterface, Infrastructure::Storagelink
Instance Attribute Summary collapse
-
#rel ⇒ Object
Returns the value of attribute rel.
-
#source ⇒ String
Source attribute of the link.
-
#target ⇒ String
Target attribute of the link.
Attributes inherited from Entity
#actions, #attributes, #id, #kind, #mixins, #model
Instance Method Summary collapse
-
#as_json(options = { }) ⇒ Hashie::Mash
Json representation.
- #check ⇒ Object
-
#initialize(kind = self.kind, mixins = [], attributes = { }, actions = [], rel = nil, target = nil, source = nil) ⇒ Link
constructor
A new instance of Link.
-
#to_string ⇒ String
Text representation of link reference.
-
#to_text_link ⇒ String
Text representation of link.
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.
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
#rel ⇒ Object
Returns the value of attribute rel.
5 6 7 |
# File 'lib/occi/core/link.rb', line 5 def rel @rel end |
#source ⇒ String
Returns source attribute of the link.
48 49 50 |
# File 'lib/occi/core/link.rb', line 48 def source @source end |
#target ⇒ String
Returns 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.
67 68 69 70 71 72 73 |
# File 'lib/occi/core/link.rb', line 67 def as_json(={ }) 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 |
#check ⇒ Object
60 61 62 63 |
# File 'lib/occi/core/link.rb', line 60 def check raise "rel must be provided" unless @rel super end |
#to_string ⇒ String
Returns 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 |
#to_text_link ⇒ String
Returns text representation of link.
94 95 96 |
# File 'lib/occi/core/link.rb', line 94 def to_text_link 'Link: ' + self.to_string end |