Class: Axlsx::Hyperlink

Inherits:
Object
  • Object
show all
Defined in:
lib/axlsx/drawing/hyperlink.rb

Overview

Note:

using the hyperlink option when calling add_image on a drawing object is the recommended way to manage hyperlinks

a hyperlink object adds an action to an image when clicked so that when the image is clicked the link is fecthed.

See Also:

  • README

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, options = {}) {|_self| ... } ⇒ Hyperlink

Creates a hyperlink object parent must be a Pic for now, although I expect that other object support this tag and its cNvPr parent

Parameters:

  • parent (Pic)
  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • tooltip (String)

    message shown when hyperlinked object is hovered over with mouse.

  • tgtFrame (String)

    Target frame for opening hyperlink

  • invalidUrl (String)

    supposedly use to store the href when we know it is an invalid resource.

  • href (String)

    the target resource this hyperlink links to.

  • action (String)

    A string that can be used to perform specific actions. For excel please see this reference: msdn.microsoft.com/en-us/library/ff532419%28v=office.12%29.aspx

  • endSnd (Boolean)

    terminate any sound events when processing this link

  • history (Boolean)

    include this link in the list of visited links for the applications history.

  • highlightClick (Boolean)

    indicate that the link has already been visited.

Yields:

  • (_self)

Yield Parameters:



66
67
68
69
70
71
72
73
74
# File 'lib/axlsx/drawing/hyperlink.rb', line 66

def initialize(parent, options={})
  DataTypeValidator.validate "Hyperlink.parent", [Pic], parent
  @parent = parent
  options.each do |o|
    self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
  end
  yield self if block_given?

end

Instance Attribute Details

#actionString

An action to take when the link is clicked. The specification says “This can be used to specify a slide to be navigated to or a script of code to be run.” but in most cases you will not need to do anything with this. MS does reserve a few interesting strings. @see msdn.microsoft.com/en-us/library/ff532419%28v=office.12%29.aspx

Returns:

  • (String)


20
21
22
# File 'lib/axlsx/drawing/hyperlink.rb', line 20

def action
  @action
end

#endSndBoolean

Specifies if all sound events should be terminated when this link is clicked.

Returns:

  • (Boolean)


24
25
26
# File 'lib/axlsx/drawing/hyperlink.rb', line 24

def endSnd
  @endSnd
end

#highlightClickBoolean

indicates that the link has already been clicked.

Returns:

  • (Boolean)


33
34
35
# File 'lib/axlsx/drawing/hyperlink.rb', line 33

def highlightClick
  @highlightClick
end

#historyBoolean

From the specs: Specifies whether to add this URI to the history when navigating to it. This allows for the viewing of this presentation without the storing of history information on the viewing machine. If this attribute is omitted, then a value of 1 or true is assumed.

Returns:

  • (Boolean)


41
42
43
# File 'lib/axlsx/drawing/hyperlink.rb', line 41

def history
  @history
end

#hrefString

The destination of the hyperlink stored in the drawing’s relationships document.

Returns:

  • (String)


10
11
12
# File 'lib/axlsx/drawing/hyperlink.rb', line 10

def href
  @href
end

#invalidUrlString

The spec says: Specifies the URL when it has been determined by the generating application that the URL is invalid. That is the generating application can still store the URL but it is known that this URL is not correct.

What exactly that means is beyond me so if you ever use this, let me know!

Returns:

  • (String)


16
17
18
# File 'lib/axlsx/drawing/hyperlink.rb', line 16

def invalidUrl
  @invalidUrl
end

#tgtFrameString

From the specs: Specifies the target frame that is to be used when opening this hyperlink. When the hyperlink is activated this attribute is used to determine if a new window is launched for viewing or if an existing one can be used. If this attribute is omitted, than a new window is opened.

Returns:

  • (String)


49
50
51
# File 'lib/axlsx/drawing/hyperlink.rb', line 49

def tgtFrame
  @tgtFrame
end

#tooltipString

Text to show when you mouse over the hyperlink. If you do not set this, the href property will be shown.

Returns:

  • (String)


53
54
55
# File 'lib/axlsx/drawing/hyperlink.rb', line 53

def tooltip
  @tooltip
end

Instance Method Details

#to_xml_string(str = '') ⇒ String

Serializes the object

Parameters:

  • str (String) (defaults to: '')

Returns:

  • (String)


79
80
81
82
83
84
85
86
# File 'lib/axlsx/drawing/hyperlink.rb', line 79

def to_xml_string(str = '')
  h =  self.instance_values.merge({:'r:id' => "rId#{id}", :'xmlns:r' => XML_NS_R })
  h.delete('href')
  h.delete('parent')
  str << '<a:hlinkClick '
  str << h.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
  str << '/>'
end