Class: Axlsx::WorksheetHyperlink
- Inherits:
-
Object
- Object
- Axlsx::WorksheetHyperlink
- 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
-
#ref ⇒ String
Cell location of hyperlink on worksheet.
Instance Method Summary collapse
-
#initialize(worksheet, options = {}) {|_self| ... } ⇒ WorksheetHyperlink
constructor
Creates a new hyperlink object.
-
#location_or_id ⇒ Hash
The values to be used in serialization based on the target.
-
#relationship ⇒ Relationship
The relationship instance for this hyperlink.
-
#target=(target) ⇒ Object
Sets the target for this hyperlink.
-
#to_xml_string(str = +'')) ⇒ String
Seralize the object.
Methods included from SerializedAttributes
included, #serialized_attributes, #serialized_element_attributes, #serialized_tag
Methods included from OptionsParser
Constructor Details
#initialize(worksheet, options = {}) {|_self| ... } ⇒ WorksheetHyperlink
the preferred way to add hyperlinks to your worksheet is the Worksheet#add_hyperlink method
Creates a new hyperlink object.
18 19 20 21 22 23 24 |
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb', line 18 def initialize(worksheet, = {}) DataTypeValidator.validate "Hyperlink.worksheet", [Worksheet], worksheet @worksheet = worksheet @target = :external yield self if block_given? end |
Instance Attribute Details
#ref ⇒ String
Cell location of hyperlink on worksheet.
32 33 34 |
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb', line 32 def ref @ref end |
Instance Method Details
#location_or_id ⇒ Hash
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.
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 |
#relationship ⇒ Relationship
The relationship instance for this hyperlink.
A relationship is only required if @target
is :external
. If not, this method will simply return nil
.
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.
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
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 |