Class: Wiki::Api::PageLink

Inherits:
Object
  • Object
show all
Defined in:
lib/wiki/api/page_link.rb

Overview

Link on a wiki page (a href=xxx)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ PageLink

Returns a new instance of PageLink.



9
10
11
12
# File 'lib/wiki/api/page_link.rb', line 9

def initialize(options = {})
  self.element = options[:element] if options.include?(:element)
  self.parent = options[:parent] if options.include?(:parent)
end

Instance Attribute Details

#elementObject

Returns the value of attribute element.



7
8
9
# File 'lib/wiki/api/page_link.rb', line 7

def element
  @element
end

#parentObject

Returns the value of attribute parent.



7
8
9
# File 'lib/wiki/api/page_link.rb', line 7

def parent
  @parent
end

Instance Method Details

#htmlObject



32
33
34
# File 'lib/wiki/api/page_link.rb', line 32

def html
  "<a href=\"#{uri}\" alt=\"#{title}\">#{title}</a>"
end

#titleObject



25
26
27
28
29
30
# File 'lib/wiki/api/page_link.rb', line 25

def title
  # skip links with no title
  return '' if element.attributes['title'].nil?

  element.attributes['title'].value
end

#to_textObject



14
15
16
# File 'lib/wiki/api/page_link.rb', line 14

def to_text
  Wiki::Api::Util.element_to_text(element)
end

#uriObject



18
19
20
21
22
23
# File 'lib/wiki/api/page_link.rb', line 18

def uri
  # lookup the root parent, and get connector info
  host = Wiki::Api::Util.parent_root(self).connect.uri
  href_value = element.attributes['href'].value
  URI.parse("#{host}#{href_value}")
end