Class: Axlsx::WorksheetHyperlink

Inherits:
Object
  • Object
show all
Includes:
Accessors, OptionsParser, SerializedAttributes
Defined in:
lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb

Overview

A worksheet hyperlink object. Note that this is not the same as a drawing hyperlink object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SerializedAttributes

included, #serialized_attributes, #serialized_element_attributes, #serialized_tag

Methods included from OptionsParser

#parse_options

Constructor Details

#initialize(worksheet, options = {}) {|_self| ... } ⇒ WorksheetHyperlink

Note:

the preferred way to add hyperlinks to your worksheet is the Worksheet#add_hyperlink method

Creates a new hyperlink object.

Parameters:

  • worksheet (Worksheet)

    the Worksheet that owns this hyperlink

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

    options to use when creating this hyperlink

  • [String] (Hash)

    a customizable set of options

  • [Symbol] (Hash)

    a customizable set of options

  • [String|Cell] (Hash)

    a customizable set of options

Yields:

  • (_self)

Yield Parameters:



18
19
20
21
22
23
24
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb', line 18

def initialize(worksheet, options = {})
  DataTypeValidator.validate "Hyperlink.worksheet", [Worksheet], worksheet
  @worksheet = worksheet
  @target = :external
  parse_options options
  yield self if block_given?
end

Instance Attribute Details

#refString

Cell location of hyperlink on worksheet.

Returns:

  • (String)


32
33
34
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb', line 32

def ref
  @ref
end

Instance Method Details

#location_or_idHash

The values to be used in serialization based on the target. location should only be specified for non-external targets. r:id should only be specified for external targets.

Returns:

  • (Hash)


71
72
73
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb', line 71

def location_or_id
  @target == :external ? { "r:id": relationship.Id } : { location: Axlsx.coder.encode(location) }
end

#relationshipRelationship

The relationship instance for this hyperlink. A relationship is only required if @target is :external. If not, this method will simply return nil.

Returns:

See Also:



52
53
54
55
56
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb', line 52

def relationship
  return unless @target == :external

  Relationship.new(self, HYPERLINK_R, location, target_mode: :External)
end

#target=(target) ⇒ Object

Sets the target for this hyperlink. Anything other than :external instructs the library to treat the location as an in-workbook reference.

Parameters:

  • target (Symbol)


36
37
38
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb', line 36

def target=(target)
  @target = target
end

#to_xml_string(str = +'')) ⇒ String

Seralize the object

Parameters:

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

Returns:

  • (String)


61
62
63
64
65
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb', line 61

def to_xml_string(str = +'')
  str << '<hyperlink '
  serialized_attributes str, location_or_id, false
  str << '/>'
end