Class: RubyDocx::Elements::Link

Inherits:
Element
  • Object
show all
Defined in:
lib/ruby_docx/elements/link.rb

Instance Attribute Summary collapse

Attributes inherited from Element

#doc, #grid, #node, #style

Instance Method Summary collapse

Methods inherited from Element

#elements, #initialize, #inspect, #to_xml

Constructor Details

This class inherits a constructor from RubyDocx::Elements::Element

Instance Attribute Details

#contentObject

Returns the value of attribute content.



3
4
5
# File 'lib/ruby_docx/elements/link.rb', line 3

def content
  @content
end

#hrefObject

Returns the value of attribute href.



3
4
5
# File 'lib/ruby_docx/elements/link.rb', line 3

def href
  @href
end

#html_contentObject

Returns the value of attribute html_content.



3
4
5
# File 'lib/ruby_docx/elements/link.rb', line 3

def html_content
  @html_content
end

Instance Method Details

#elementObject



5
6
7
# File 'lib/ruby_docx/elements/link.rb', line 5

def element
  @element ||= @node.children.first
end

#replace(url) ⇒ Object



33
34
35
# File 'lib/ruby_docx/elements/link.rb', line 33

def replace(url)
  self.href = url
end

#to_htmlObject



37
38
39
40
41
42
43
44
45
# File 'lib/ruby_docx/elements/link.rb', line 37

def to_html
  if !self.href
    "#{self.html_content}"
  elsif self.href.to_s =~ /^http/
    "<a href=\"#{self.href}\">#{self.html_content}</a>"
  else
    "<a href=\"##{self.href}\">#{self.html_content}</a>"
  end
end

#to_sObject



47
48
49
# File 'lib/ruby_docx/elements/link.rb', line 47

def to_s
  self.content.to_s
end