Class: Axlsx::WorksheetHyperlink
- Inherits:
-
Object
- Object
- Axlsx::WorksheetHyperlink
- 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.
Constant Summary collapse
- STRING_ATTRIBUTES =
String attributes for this object
%w(display location tooltip)
Instance Attribute Summary collapse
-
#ref ⇒ String
Cell location of hyperlink on worksheet.
Instance Method Summary collapse
-
#id ⇒ String
The id of the relationship for this object.
-
#initialize(worksheet, options = {}) {|_self| ... } ⇒ WorksheetHyperlink
constructor
Creates a new hyperlink object.
-
#relationship ⇒ Relationship
The relationship required by this hyperlink when the taget is :external.
-
#serialization_values ⇒ Hash
The values to be used in serialization based on the target.
-
#target=(target) ⇒ Object
Sets the target for this hyperlink.
-
#to_xml_string(str = '') ⇒ String
Seralize the object.
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.
15 16 17 18 19 20 21 22 23 |
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb', line 15 def initialize(worksheet, ={}) DataTypeValidator.validate "Hyperlink.worksheet", [Worksheet], worksheet @worksheet = worksheet @target = :external .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
#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
#id ⇒ String
The id of the relationship for this object
73 74 75 76 |
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb', line 73 def id return unless @target == :external "rId#{(@worksheet.relationships_index_of(self)+1)}" end |
#relationship ⇒ Relationship
The relationship required by this hyperlink when the taget is :external
66 67 68 69 |
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb', line 66 def relationship return unless @target == :external Relationship.new HYPERLINK_R, location, :target_mode => :External end |
#serialization_values ⇒ 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.
91 92 93 94 95 96 97 98 99 |
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb', line 91 def serialization_values h = instance_values.reject { |key, value| !%w(display ref tooltip).include?(key) } if @target == :external h['r:id'] = id else h['location'] = location end h 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
81 82 83 84 85 |
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb', line 81 def to_xml_string(str='') str << '<hyperlink ' serialization_values.map { |key, value| str << key.to_s << '="' << value.to_s << '" ' } str << '/>' end |