From e4d4538e1ea15b6aff9e4ef3fbc47c2e29ceb8be Mon Sep 17 00:00:00 2001 From: Randy Morgan Date: Sun, 14 Oct 2012 11:28:02 +0900 Subject: Refactored to use options parser --- lib/axlsx/drawing/chart.rb | 5 ++--- lib/axlsx/drawing/d_lbls.rb | 6 ++---- lib/axlsx/stylesheet/border.rb | 37 ++++++++++++++++++------------------- 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/lib/axlsx/drawing/chart.rb b/lib/axlsx/drawing/chart.rb index 8566b3f3..35e2089a 100644 --- a/lib/axlsx/drawing/chart.rb +++ b/lib/axlsx/drawing/chart.rb @@ -6,6 +6,7 @@ module Axlsx # @see README for examples class Chart + include Axlsx::OptionsParser # Creates a new chart object # @param [GraphicalFrame] frame The frame that holds this chart. # @option options [Cell, String] title @@ -21,9 +22,7 @@ module Axlsx @show_legend = true @series_type = Series @title = Title.new - options.each do |o| - self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}=" - end + parse_options options start_at(*options[:start_at]) if options[:start_at] end_at(*options[:end_at]) if options[:end_at] yield self if block_given? diff --git a/lib/axlsx/drawing/d_lbls.rb b/lib/axlsx/drawing/d_lbls.rb index 2074b85d..3685e7d2 100644 --- a/lib/axlsx/drawing/d_lbls.rb +++ b/lib/axlsx/drawing/d_lbls.rb @@ -7,15 +7,13 @@ module Axlsx class DLbls include Axlsx::Accessors - + include Axlsx::OptionsParser # creates a new DLbls object def initialize(chart_type, options={}) raise ArgumentError, 'chart_type must inherit from Chart' unless chart_type.superclass == Chart @chart_type = chart_type initialize_defaults - options.each do |o| - self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}=" - end + parse_options options end # These attributes are all boolean so I'm doing a bit of a hand diff --git a/lib/axlsx/stylesheet/border.rb b/lib/axlsx/stylesheet/border.rb index 6c104263..422a4466 100644 --- a/lib/axlsx/stylesheet/border.rb +++ b/lib/axlsx/stylesheet/border.rb @@ -4,22 +4,7 @@ module Axlsx class Border include Axlsx::SerializedAttributes - - serializable_attributes :diagonal_up, :diagonal_down, :outline - - # @return [Boolean] The diagonal up property for the border that indicates if the border should include a diagonal line from the bottom left to the top right of the cell. - attr_reader :diagonal_up - alias :diagonalUp :diagonal_up - - # @return [Boolean] The diagonal down property for the border that indicates if the border should include a diagonal line from the top left to the top right of the cell. - attr_reader :diagonal_down - alias :diagonalDown :diagonal_down - - # @return [Boolean] The outline property for the border indicating that top, left, right and bottom borders should only be applied to the outside border of a range of cells. - attr_reader :outline - - # @return [SimpleTypedList] A list of BorderPr objects for this border. - attr_reader :prs + include Axlsx::OptionsParser # Creates a new Border object # @option options [Boolean] diagonal_up @@ -36,11 +21,25 @@ module Axlsx # @see Style#add_style def initialize(options={}) @prs = SimpleTypedList.new BorderPr - options.each do |o| - self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}=" - end + parse_options options end + serializable_attributes :diagonal_up, :diagonal_down, :outline + + # @return [Boolean] The diagonal up property for the border that indicates if the border should include a diagonal line from the bottom left to the top right of the cell. + attr_reader :diagonal_up + alias :diagonalUp :diagonal_up + + # @return [Boolean] The diagonal down property for the border that indicates if the border should include a diagonal line from the top left to the top right of the cell. + attr_reader :diagonal_down + alias :diagonalDown :diagonal_down + + # @return [Boolean] The outline property for the border indicating that top, left, right and bottom borders should only be applied to the outside border of a range of cells. + attr_reader :outline + + # @return [SimpleTypedList] A list of BorderPr objects for this border. + attr_reader :prs + # @see diagonalUp def diagonal_up=(v) Axlsx::validate_boolean v; @diagonal_up = v end alias :diagonalUp= :diagonal_up= -- cgit v1.2.3