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
#declared_attributes, 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.
16 17 18 19 20 21 22 |
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb', line 16 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.
30 31 32 |
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb', line 30 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.
69 70 71 |
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb', line 69 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
.
50 51 52 53 54 |
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb', line 50 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.
34 35 36 |
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb', line 34 def target=(target) @target = target end |
#to_xml_string(str = '') ⇒ String
Seralize the object
59 60 61 62 63 |
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb', line 59 def to_xml_string(str = '') str << '<hyperlink ' serialized_attributes str, location_or_id str << '/>' end |