summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--lib/axlsx.rb2
-rw-r--r--lib/axlsx/drawing/d_lbls.rb17
-rw-r--r--lib/axlsx/util/boolean_attributes.rb21
-rw-r--r--lib/axlsx/workbook/defined_name.rb19
-rw-r--r--lib/axlsx/workbook/worksheet/sheet_pr.rb18
-rw-r--r--lib/axlsx/workbook/worksheet/table_style_info.rb22
6 files changed, 36 insertions, 63 deletions
diff --git a/lib/axlsx.rb b/lib/axlsx.rb
index 1fd9051e..fe6f8ec3 100644
--- a/lib/axlsx.rb
+++ b/lib/axlsx.rb
@@ -5,7 +5,7 @@ require 'axlsx/version.rb'
require 'axlsx/util/simple_typed_list.rb'
require 'axlsx/util/constants.rb'
require 'axlsx/util/validators.rb'
-
+require 'axlsx/util/boolean_attributes.rb'
# to be included with parsable intitites.
#require 'axlsx/util/parser.rb'
diff --git a/lib/axlsx/drawing/d_lbls.rb b/lib/axlsx/drawing/d_lbls.rb
index 531c5674..7dccf911 100644
--- a/lib/axlsx/drawing/d_lbls.rb
+++ b/lib/axlsx/drawing/d_lbls.rb
@@ -7,14 +7,6 @@ module Axlsx
# showLeaderLines and leaderLines are not currently implemented
class DLbls
- # These attributes are all boolean so I'm doing a bit of a hand
- # waving magic show to set up the attriubte accessors
- # @note
- # not all charts support all methods!
- # Bar3DChart and Line3DChart and ScatterChart do not support d_lbl_pos or show_leader_lines
- #
- BOOLEAN_ATTRIBUTES = [:show_legend_key, :show_val, :show_cat_name, :show_ser_name, :show_percent, :show_bubble_size, :show_leader_lines]
-
# creates a new DLbls object
def initialize(chart_type, options={})
raise ArgumentError, 'chart_type must inherit from Chart' unless chart_type.superclass == Chart
@@ -25,6 +17,15 @@ module Axlsx
end
end
+ # These attributes are all boolean so I'm doing a bit of a hand
+ # waving magic show to set up the attriubte accessors
+ # @note
+ # not all charts support all methods!
+ # Bar3DChart and Line3DChart and ScatterChart do not support d_lbl_pos or show_leader_lines
+ #
+ BOOLEAN_ATTRIBUTES = [:show_legend_key, :show_val, :show_cat_name, :show_ser_name, :show_percent, :show_bubble_size, :show_leader_lines]
+ include BooleanAttributes
+
# Initialize all the values to false as Excel requires them to
# explicitly be disabled or all will show.
def initialize_defaults
diff --git a/lib/axlsx/util/boolean_attributes.rb b/lib/axlsx/util/boolean_attributes.rb
new file mode 100644
index 00000000..3d671aba
--- /dev/null
+++ b/lib/axlsx/util/boolean_attributes.rb
@@ -0,0 +1,21 @@
+module Axlsx
+ module BooleanAttributes
+ def BooleanAttributes.included(mod)
+ mod::BOOLEAN_ATTRIBUTES.each do |attr|
+ class_eval %{
+ # The #{attr} attribute reader
+ # @return [Boolean]
+ attr_reader :#{attr}
+
+ # The #{attr} writer
+ # @param [Boolean] value The value to assign to #{attr}
+ # @return [Boolean]
+ def #{attr}=(value)
+ Axlsx::validate_boolean(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 10a84b3c..c8516afb 100644
--- a/lib/axlsx/workbook/defined_name.rb
+++ b/lib/axlsx/workbook/defined_name.rb
@@ -114,7 +114,7 @@ module Axlsx
# 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 %{
@@ -132,23 +132,6 @@ module Axlsx
}
end
- # Dynamically create boolean attribute accessors
- BOOLEAN_ATTRIBUTES.each do |attr|
- class_eval %{
- # The #{attr} attribute reader
- # @return [Boolean]
- attr_reader :#{attr}
-
- # The #{attr} writer
- # @param [Boolean] value The value to assign to #{attr}
- # @return [Boolean]
- def #{attr}=(value)
- Axlsx::validate_boolean(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/sheet_pr.rb b/lib/axlsx/workbook/worksheet/sheet_pr.rb
index d36b3a43..a62f4fe9 100644
--- a/lib/axlsx/workbook/worksheet/sheet_pr.rb
+++ b/lib/axlsx/workbook/worksheet/sheet_pr.rb
@@ -14,6 +14,7 @@ module Axlsx
:filter_mode,
:enable_format_conditions_calculation]
+ include BooleanAttributes
# Creates a new SheetPr object
# @param [Worksheet] worksheet The worksheet that owns this SheetPr object
@@ -26,23 +27,6 @@ module Axlsx
end
end
- # Dynamically create accessors for boolean attriubtes
- BOOLEAN_ATTRIBUTES.each do |attr|
- class_eval %{
- # The #{attr} attribute reader
- # @return [Boolean]
- attr_reader :#{attr}
-
- # The #{attr} writer
- # @param [Boolean] value The value to assign to #{attr}
- # @return [Boolean]
- def #{attr}=(value)
- Axlsx::validate_boolean(value)
- @#{attr} = value
- end
- }
- end
-
# Anchor point for worksheet's window.
# @return [String]
attr_reader :code_name
diff --git a/lib/axlsx/workbook/worksheet/table_style_info.rb b/lib/axlsx/workbook/worksheet/table_style_info.rb
index 0f39f0df..4bb34580 100644
--- a/lib/axlsx/workbook/worksheet/table_style_info.rb
+++ b/lib/axlsx/workbook/worksheet/table_style_info.rb
@@ -4,9 +4,6 @@ module Axlsx
# a worksheet
class TableStyleInfo
- # boolean attributes for this object
- BOOLEAN_ATTRIBUTES = %w(show_first_column show_last_column show_row_stripes show_column_stripes)
-
# creates a new TableStyleInfo instance
# @param [Hash] options
# @option [Boolean] show_first_column indicates if the first column should
@@ -27,22 +24,9 @@ module Axlsx
end
end
- # Dynamically create accessors for boolean attriubtes
- BOOLEAN_ATTRIBUTES.each do |attr|
- class_eval %{
- # The #{attr} attribute reader
- # @return [Boolean]
- attr_reader :#{attr}
-
- # The #{attr} writer
- # @param [Boolean] value The value to assign to #{attr}
- # @return [Boolean]
- def #{attr}=(value)
- Axlsx::validate_boolean(value)
- @#{attr} = value
- end
- }
- end
+ # boolean attributes for this object
+ BOOLEAN_ATTRIBUTES = %w(show_first_column show_last_column show_row_stripes show_column_stripes)
+ include BooleanAttributes
# Initialize all the values to false as Excel requires them to
# explicitly be disabled or all will show.