diff options
| author | Randy Morgan <[email protected]> | 2012-10-09 21:50:25 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-10-09 21:50:25 +0900 |
| commit | be95b7eaa72cd7007bc0fef22d0c3ea4fa3c3553 (patch) | |
| tree | 4553f0ec8767385961e08162ebfa65eb96c77420 | |
| parent | f0bc5f17ddafd8172646a04bbbc0d3b958c0205f (diff) | |
| download | caxlsx-be95b7eaa72cd7007bc0fef22d0c3ea4fa3c3553.tar.gz caxlsx-be95b7eaa72cd7007bc0fef22d0c3ea4fa3c3553.zip | |
extracted accessor methods into module that is scope because polluting Module or Class is just not cool
| -rw-r--r-- | lib/axlsx.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/drawing/d_lbls.rb | 3 | ||||
| -rw-r--r-- | lib/axlsx/util/accessors.rb | 26 | ||||
| -rw-r--r-- | lib/axlsx/util/module.rb | 18 | ||||
| -rw-r--r-- | lib/axlsx/workbook/defined_name.rb | 3 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/sheet_pr.rb | 3 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/table_style_info.rb | 1 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb | 1 |
8 files changed, 36 insertions, 21 deletions
diff --git a/lib/axlsx.rb b/lib/axlsx.rb index 2c64a193..394a0806 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/module.rb' +require 'axlsx/util/accessors.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 cb0f9ad5..2074b85d 100644 --- a/lib/axlsx/drawing/d_lbls.rb +++ b/lib/axlsx/drawing/d_lbls.rb @@ -2,11 +2,12 @@ module Axlsx # There are more elements in the dLbls spec that allow for # customizations and formatting. For now, I am just implementing the # basics. - #The DLbls class manages serialization of data labels # showLeaderLines and leaderLines are not currently implemented class DLbls + include Axlsx::Accessors + # creates a new DLbls object def initialize(chart_type, options={}) raise ArgumentError, 'chart_type must inherit from Chart' unless chart_type.superclass == Chart diff --git a/lib/axlsx/util/accessors.rb b/lib/axlsx/util/accessors.rb new file mode 100644 index 00000000..3096d9c7 --- /dev/null +++ b/lib/axlsx/util/accessors.rb @@ -0,0 +1,26 @@ +module Axlsx + module Accessors + def self.included(base) + base.send :extend, ClassMethods + end + + module ClassMethods + def string_attr_accessor(*symbols) + validated_attr_accessor(symbols, 'validate_string') + end + + def boolean_attr_accessor(*symbols) + validated_attr_accessor(symbols, 'validate_boolean') + end + + SETTER = "def %s=(value) Axlsx::%s(value); @%s = value; end" + def validated_attr_accessor(symbols, validator) + symbols.each do |symbol| + attr_reader symbol + module_eval(SETTER % [symbol.to_s, validator, symbol.to_s], __FILE__, __LINE__) + end + end + end + end +end + diff --git a/lib/axlsx/util/module.rb b/lib/axlsx/util/module.rb deleted file mode 100644 index 4f3543a0..00000000 --- a/lib/axlsx/util/module.rb +++ /dev/null @@ -1,18 +0,0 @@ -class Module - def string_attr_accessor(*symbols) - validated_attr_accessor(symbols, 'validate_string') - end - - def boolean_attr_accessor(*symbols) - validated_attr_accessor(symbols, 'validate_boolean') - end - - SETTER = "def %s=(value) Axlsx::%s(value); @%s = value; end" - def validated_attr_accessor(symbols, validator) - symbols.each do |symbol| - attr_reader symbol - module_eval(SETTER % [symbol.to_s, validator, symbol.to_s], __FILE__, __LINE__) - end - end - -end diff --git a/lib/axlsx/workbook/defined_name.rb b/lib/axlsx/workbook/defined_name.rb index 81265280..8a1f57d4 100644 --- a/lib/axlsx/workbook/defined_name.rb +++ b/lib/axlsx/workbook/defined_name.rb @@ -49,6 +49,9 @@ module Axlsx # @example # For clarification: LOG10 is always a cell reference, LOG10() is always formula, LOGO1000 can be a defined name that overrides a cell reference. class DefinedName + + + include Axlsx::Accessors # creates a new DefinedName. # @param [String] formula - the formula the defined name references # @param [Hash] options - A hash of key/value pairs that will be mapped to this instances attributes. diff --git a/lib/axlsx/workbook/worksheet/sheet_pr.rb b/lib/axlsx/workbook/worksheet/sheet_pr.rb index 94b33f5e..79e10ca0 100644 --- a/lib/axlsx/workbook/worksheet/sheet_pr.rb +++ b/lib/axlsx/workbook/worksheet/sheet_pr.rb @@ -2,7 +2,8 @@ module Axlsx # The SheetPr class manages serialization fo a worksheet's sheetPr element. class SheetPr - + + include Axlsx::Accessors # These attributes are all boolean so I'm doing a bit of a hand # waving magic show to set up the attriubte accessors diff --git a/lib/axlsx/workbook/worksheet/table_style_info.rb b/lib/axlsx/workbook/worksheet/table_style_info.rb index 82320b56..a9e3d8b7 100644 --- a/lib/axlsx/workbook/worksheet/table_style_info.rb +++ b/lib/axlsx/workbook/worksheet/table_style_info.rb @@ -4,6 +4,7 @@ module Axlsx # a worksheet class TableStyleInfo + include Axlsx::Accessors # creates a new TableStyleInfo instance # @param [Hash] options # @option [Boolean] show_first_column indicates if the first column should diff --git a/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb b/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb index 73f769ce..71bb0a51 100644 --- a/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +++ b/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb @@ -3,6 +3,7 @@ module Axlsx # A worksheet hyperlink object. Note that this is not the same as a drawing hyperlink object. class WorksheetHyperlink + include Axlsx::Accessors # 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 |
