summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-10-14 08:46:04 +0900
committerRandy Morgan <[email protected]>2012-10-14 08:46:04 +0900
commitfbb4b8455c34e86fb9db541a9ce508beca0de6ac (patch)
tree94fd6169064b569bfaf4b736bdae6a397c98ae95
parentef503bd236e5130d92c7c5f057a839aa17064555 (diff)
downloadcaxlsx-fbb4b8455c34e86fb9db541a9ce508beca0de6ac.tar.gz
caxlsx-fbb4b8455c34e86fb9db541a9ce508beca0de6ac.zip
Applied serialized_attributes to worksheet_hyperlink
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb21
1 files changed, 9 insertions, 12 deletions
diff --git a/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb b/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb
index 71bb0a51..4807d58d 100644
--- a/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb
@@ -3,7 +3,9 @@ module Axlsx
# A worksheet hyperlink object. Note that this is not the same as a drawing hyperlink object.
class WorksheetHyperlink
+
include Axlsx::Accessors
+ include Axlsx::SerializedAttributes
# Creates a new hyperlink object.
# @note the preferred way to add hyperlinks to your worksheet is the Worksheet#add_hyperlink method
# @param [Worksheet] worksheet the Worksheet that owns this hyperlink
@@ -22,9 +24,11 @@ module Axlsx
end
yield self if block_given?
end
-
+
string_attr_accessor :display, :location, :tooltip
-
+
+ serializable_attributes :display, :tooltip, :ref
+
#Cell location of hyperlink on worksheet.
# @return [String]
attr_reader :ref
@@ -39,7 +43,6 @@ module Axlsx
# @param [String|Cell] cell_reference The string reference or cell that defines where this hyperlink shows in the worksheet.
def ref=(cell_reference)
cell_reference = cell_reference.r if cell_reference.is_a?(Cell)
-
Axlsx::validate_string cell_reference
@ref = cell_reference
end
@@ -63,7 +66,7 @@ module Axlsx
# @return [String]
def to_xml_string(str='')
str << '<hyperlink '
- serialization_values.map { |key, value| str << key.to_s << '="' << value.to_s << '" ' }
+ serialized_attributes str, location_or_id
str << '/>'
end
@@ -71,14 +74,8 @@ module Axlsx
# location should only be specified for non-external targets.
# r:id should only be specified for external targets.
# @return [Hash]
- 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
+ def location_or_id
+ @target == :external ? { :"r:id" => id } : { :"location" => location }
end
end
end