summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-09-30 18:29:19 +0900
committerRandy Morgan <[email protected]>2012-09-30 18:29:19 +0900
commita942008d3b0f4618a3d35541de6f97ad487a463c (patch)
tree4444bf99b68d64d1ea072509b70cff8e2d2fd2e2 /lib
parentabc54f36bfd9975c5e2f2968cfac3405c7a4d795 (diff)
downloadcaxlsx-a942008d3b0f4618a3d35541de6f97ad487a463c.tar.gz
caxlsx-a942008d3b0f4618a3d35541de6f97ad487a463c.zip
Extracted STRING_ATTRIBUTES and BOOLEAN_ATTRIBUTES into mixin from module
replaced with attr_accessor like methods: string_attr_accessor boolean_attr_accessor defined in module.rb
Diffstat (limited to 'lib')
-rw-r--r--lib/axlsx/drawing/d_lbls.rb32
-rw-r--r--lib/axlsx/workbook/worksheet/sheet_pr.rb32
-rw-r--r--lib/axlsx/workbook/worksheet/table_style_info.rb5
3 files changed, 18 insertions, 51 deletions
diff --git a/lib/axlsx/drawing/d_lbls.rb b/lib/axlsx/drawing/d_lbls.rb
index 7dccf911..cb0f9ad5 100644
--- a/lib/axlsx/drawing/d_lbls.rb
+++ b/lib/axlsx/drawing/d_lbls.rb
@@ -23,13 +23,20 @@ module Axlsx
# 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
+ boolean_attr_accessor :show_legend_key,
+ :show_val,
+ :show_cat_name,
+ :show_ser_name,
+ :show_percent,
+ :show_bubble_size,
+ :show_leader_lines
# Initialize all the values to false as Excel requires them to
# explicitly be disabled or all will show.
def initialize_defaults
- BOOLEAN_ATTRIBUTES.each do |attr|
+ [:show_legend_key, :show_val, :show_cat_name,
+ :show_ser_name, :show_percent, :show_bubble_size,
+ :show_leader_lines].each do |attr|
self.send("#{attr}=", false)
end
end
@@ -59,24 +66,7 @@ module Axlsx
@d_lbl_pos = label_position
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
-
-
+
# serializes the data labels
# @return [String]
def to_xml_string(str = '')
diff --git a/lib/axlsx/workbook/worksheet/sheet_pr.rb b/lib/axlsx/workbook/worksheet/sheet_pr.rb
index a62f4fe9..94b33f5e 100644
--- a/lib/axlsx/workbook/worksheet/sheet_pr.rb
+++ b/lib/axlsx/workbook/worksheet/sheet_pr.rb
@@ -6,15 +6,15 @@ module Axlsx
# These attributes are all boolean so I'm doing a bit of a hand
# waving magic show to set up the attriubte accessors
- BOOLEAN_ATTRIBUTES = [:sync_horizontal,
- :sync_vertical,
- :transtion_evaluation,
+ boolean_attr_accessor :sync_horizontal,
+ :sync_vertical,
+ :transtion_evaluation,
:transition_entry,
:published,
:filter_mode,
- :enable_format_conditions_calculation]
+ :enable_format_conditions_calculation
- include BooleanAttributes
+ string_attr_accessor :code_name, :sync_ref
# Creates a new SheetPr object
# @param [Worksheet] worksheet The worksheet that owns this SheetPr object
@@ -27,32 +27,10 @@ module Axlsx
end
end
- # Anchor point for worksheet's window.
- # @return [String]
- attr_reader :code_name
-
- # Specifies a stable name of the sheet, which should not change over time,
- # and does not change from user input. This name should be used by code
- # to reference a particular sheet.
- # @return [String]
- attr_reader :sync_ref
-
# The worksheet these properties apply to!
# @return [Worksheet]
attr_reader :worksheet
- # @see code_name
- # @param [String] name
- def code_name=(name)
- @code_name = name
- end
-
- # @see sync_ref
- # @param [String] ref A cell reference (e.g. "A1")
- def sync_ref=(ref)
- @sync_ref = ref
- end
-
# Serialize the object
# @param [String] str serialized output will be appended to this object if provided.
# @return [String]
diff --git a/lib/axlsx/workbook/worksheet/table_style_info.rb b/lib/axlsx/workbook/worksheet/table_style_info.rb
index 4bb34580..82320b56 100644
--- a/lib/axlsx/workbook/worksheet/table_style_info.rb
+++ b/lib/axlsx/workbook/worksheet/table_style_info.rb
@@ -25,13 +25,12 @@ module Axlsx
end
# boolean attributes for this object
- BOOLEAN_ATTRIBUTES = %w(show_first_column show_last_column show_row_stripes show_column_stripes)
- include BooleanAttributes
+ boolean_attr_accessor :show_first_column, :show_last_column, :show_row_stripes, :show_column_stripes
# Initialize all the values to false as Excel requires them to
# explicitly be disabled or all will show.
def initialize_defaults
- BOOLEAN_ATTRIBUTES.each do |attr|
+ %w(show_first_column show_last_column show_row_stripes show_column_stripes).each do |attr|
self.send("#{attr}=", 0)
end
end