diff options
| author | Randy Morgan <[email protected]> | 2012-10-14 11:28:02 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-10-14 11:28:02 +0900 |
| commit | e4d4538e1ea15b6aff9e4ef3fbc47c2e29ceb8be (patch) | |
| tree | 92b9ef6e6a0d0329428e4ce1679cea6a0eff90e9 | |
| parent | 9740fed4e0834c0fcdce8e07153b9b794525f37e (diff) | |
| download | caxlsx-e4d4538e1ea15b6aff9e4ef3fbc47c2e29ceb8be.tar.gz caxlsx-e4d4538e1ea15b6aff9e4ef3fbc47c2e29ceb8be.zip | |
Refactored to use options parser
| -rw-r--r-- | lib/axlsx/drawing/chart.rb | 5 | ||||
| -rw-r--r-- | lib/axlsx/drawing/d_lbls.rb | 6 | ||||
| -rw-r--r-- | 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= |
