Class: Discodactyl::XRD::Link

Inherits:
Struct
  • Object
show all
Defined in:
lib/discodactyl/xrd/link.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hrefObject

Returns the value of attribute href

Returns:

  • (Object)

    the current value of href


6
7
8
# File 'lib/discodactyl/xrd/link.rb', line 6

def href
  @href
end

#rawObject

Returns the value of attribute raw


7
8
9
# File 'lib/discodactyl/xrd/link.rb', line 7

def raw
  @raw
end

#relObject

Returns the value of attribute rel

Returns:

  • (Object)

    the current value of rel


6
7
8
# File 'lib/discodactyl/xrd/link.rb', line 6

def rel
  @rel
end

#templateObject

Returns the value of attribute template

Returns:

  • (Object)

    the current value of template


6
7
8
# File 'lib/discodactyl/xrd/link.rb', line 6

def template
  @template
end

#titleObject

Returns the value of attribute title

Returns:

  • (Object)

    the current value of title


6
7
8
# File 'lib/discodactyl/xrd/link.rb', line 6

def title
  @title
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type


6
7
8
# File 'lib/discodactyl/xrd/link.rb', line 6

def type
  @type
end

Class Method Details

.parse(element) ⇒ Object


9
10
11
12
13
14
15
16
17
18
# File 'lib/discodactyl/xrd/link.rb', line 9

def parse(element)
  self.new.tap do |link|
    link.rel = element['rel']
    link.type = element['type']
    link.href = element['href']
    link.title = element['title']
    link.template = URITemplate.new(element['template']) unless link.href
    link.raw = element
  end
end

Instance Method Details

#==(other) ⇒ Object


40
41
42
43
# File 'lib/discodactyl/xrd/link.rb', line 40

def ==(other)
  (other.respond_to?('raw') && (@raw == other.raw)) ||
  super
end

#idObject


25
26
27
28
29
30
# File 'lib/discodactyl/xrd/link.rb', line 25

def id
  begin
    @raw.attribute_with_ns('id', 'http://www.w3.org/XML/1998/namespace').value
  rescue
  end
end

#id=(value) ⇒ Object


32
33
34
# File 'lib/discodactyl/xrd/link.rb', line 32

def id=(value)
  @raw['xml:id'] = value
end

#to_sObject


36
37
38
# File 'lib/discodactyl/xrd/link.rb', line 36

def to_s
  @raw.to_s
end

#to_uri(params = {}) ⇒ Object


21
22
23
# File 'lib/discodactyl/xrd/link.rb', line 21

def to_uri(params = {})
  href || template.to_uri(params)
end