summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-09-30 10:38:46 +0900
committerRandy Morgan <[email protected]>2012-09-30 10:38:46 +0900
commit0b545d70fbc0eb3506150541fb070a667299b3b6 (patch)
tree4f4641dbe87a147bda848b83e8a30930857e71d3
parenteec3a4a1e492576107e6178fe613474285f80192 (diff)
downloadcaxlsx-0b545d70fbc0eb3506150541fb070a667299b3b6.tar.gz
caxlsx-0b545d70fbc0eb3506150541fb070a667299b3b6.zip
Extracted String Attribute method generation.
-rw-r--r--lib/axlsx/util/boolean_attributes.rb22
-rw-r--r--lib/axlsx/workbook/defined_name.rb19
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb20
3 files changed, 26 insertions, 35 deletions
diff --git a/lib/axlsx/util/boolean_attributes.rb b/lib/axlsx/util/boolean_attributes.rb
index 3d671aba..48918b63 100644
--- a/lib/axlsx/util/boolean_attributes.rb
+++ b/lib/axlsx/util/boolean_attributes.rb
@@ -18,4 +18,26 @@ module Axlsx
end
end
end
+
+ module StringAttributes
+ def StringAttributes.included(mod)
+ mod::STRING_ATTRIBUTES.each do |attr|
+ class_eval %{
+ # The #{attr} attribute reader
+ # @return [String]
+ attr_reader :#{attr}
+
+ # The #{attr} writer
+ # @param [String] value The value to assign to #{attr}
+ # @return [String]
+ def #{attr}=(value)
+ Axlsx::validate_string(value)
+ @#{attr}= value
+ end
+ }
+
+ end
+ end
+ end
+
end
diff --git a/lib/axlsx/workbook/defined_name.rb b/lib/axlsx/workbook/defined_name.rb
index c8516afb..b7a752a6 100644
--- a/lib/axlsx/workbook/defined_name.rb
+++ b/lib/axlsx/workbook/defined_name.rb
@@ -111,27 +111,12 @@ module Axlsx
# string attributes that will be added when this class is evaluated
STRING_ATTRIBUTES = [:short_cut_key, :status_bar, :help, :description, :custom_menu, :comment]
+ include StringAttributes
# boolean attributes that will be added when this class is evaluated
BOOLEAN_ATTRIBUTES = [:workbook_parameter, :publish_to_server, :xlm, :vb_proceedure, :function, :hidden]
include BooleanAttributes
- # Dynamically create string attribute accessors
- STRING_ATTRIBUTES.each do |attr|
- class_eval %{
- # The #{attr} attribute reader
- # @return [String]
- attr_reader :#{attr}
-
- # The #{attr} writer
- # @param [String] value The value to assign to #{attr}
- # @return [String]
- def #{attr}=(value)
- Axlsx::validate_string(value)
- @#{attr}= value
- end
- }
- end
-
+
attr_reader :name
# The name of this defined name. Please refer to the class documentation for more information
def name=(value)
diff --git a/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb b/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb
index 5de0a6d2..42e99d08 100644
--- a/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb
@@ -24,6 +24,7 @@ module Axlsx
# String attributes for this object
STRING_ATTRIBUTES = %w(display location tooltip)
+ include StringAttributes
#Cell location of hyperlink on worksheet.
# @return [String]
@@ -44,24 +45,7 @@ module Axlsx
@ref = cell_reference
end
- # Dynamically create string attribute accessors
- STRING_ATTRIBUTES.each do |attr|
- class_eval %{
- # The #{attr} attribute reader
- # @return [String]
- attr_reader :#{attr}
-
- # The #{attr} writer
- # @param [String] value The value to assign to #{attr}
- # @return [String]
- def #{attr}=(value)
- Axlsx::validate_string(value)
- @#{attr}= value
- end
- }
- end
-
- # The relationship required by this hyperlink when the taget is :external
+ # The relationship required by this hyperlink when the taget is :external
# @return [Relationship]
def relationship
return unless @target == :external