diff options
| author | Randy Morgan <[email protected]> | 2012-10-14 09:50:49 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-10-14 09:50:49 +0900 |
| commit | 797a1e5150fc617774fcb8ee2bcce3fddb7ab531 (patch) | |
| tree | 07d6e953abbb4afba309fb34d2833193358b045c | |
| parent | 87560296ccb05a4fb21461bc64aead272a5839b7 (diff) | |
| download | caxlsx-797a1e5150fc617774fcb8ee2bcce3fddb7ab531.tar.gz caxlsx-797a1e5150fc617774fcb8ee2bcce3fddb7ab531.zip | |
Refactored options parse into module and applied it to border_rb
This should be done for all classes that use this same peice of
repeated code.
| -rw-r--r-- | lib/axlsx.rb | 1 | ||||
| -rw-r--r-- | lib/axlsx/stylesheet/border_pr.rb | 9 | ||||
| -rw-r--r-- | lib/axlsx/util/options_parser.rb | 9 |
3 files changed, 15 insertions, 4 deletions
diff --git a/lib/axlsx.rb b/lib/axlsx.rb index 00438425..20129b95 100644 --- a/lib/axlsx.rb +++ b/lib/axlsx.rb @@ -7,6 +7,7 @@ require 'axlsx/util/constants.rb' require 'axlsx/util/validators.rb' require 'axlsx/util/accessors.rb' require 'axlsx/util/serialized_attributes' +require 'axlsx/util/options_parser' # to be included with parsable intitites. #require 'axlsx/util/parser.rb' diff --git a/lib/axlsx/stylesheet/border_pr.rb b/lib/axlsx/stylesheet/border_pr.rb index eb1ecf4b..12b20d09 100644 --- a/lib/axlsx/stylesheet/border_pr.rb +++ b/lib/axlsx/stylesheet/border_pr.rb @@ -2,7 +2,7 @@ module Axlsx # A border part. class BorderPr - + include Axlsx::OptionsParser # @return [Color] The color of this border part. attr_reader :color @@ -45,9 +45,10 @@ module Axlsx # @option options [Symbol] style # @see Axlsx::Border def initialize(options={}) - options.each do |o| - self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}=" - end + parse_options(options) + #options.each do |o| + # self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}=" + #end end # @see name diff --git a/lib/axlsx/util/options_parser.rb b/lib/axlsx/util/options_parser.rb new file mode 100644 index 00000000..c4c43fa2 --- /dev/null +++ b/lib/axlsx/util/options_parser.rb @@ -0,0 +1,9 @@ +module Axlsx + module OptionsParser + def parse_options(options={}) + options.each do |o| + self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}=" + end + end + end +end |
