From a4e21e2e93ae227fb3e3bdf957c4e0b93fb0c90c Mon Sep 17 00:00:00 2001 From: Randy Morgan Date: Sun, 14 Oct 2012 11:07:29 +0900 Subject: Refactored GradientFill to use options parser and serialized attributes and patched type on Cfvo --- lib/axlsx/stylesheet/gradient_fill.rb | 38 ++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'lib/axlsx/stylesheet/gradient_fill.rb') diff --git a/lib/axlsx/stylesheet/gradient_fill.rb b/lib/axlsx/stylesheet/gradient_fill.rb index 41c1bb46..b4990a82 100644 --- a/lib/axlsx/stylesheet/gradient_fill.rb +++ b/lib/axlsx/stylesheet/gradient_fill.rb @@ -4,6 +4,24 @@ module Axlsx # @see Open Office XML Part 1 ยง18.8.24 class GradientFill + include Axlsx::OptionsParser + include Axlsx::SerializedAttributes + + # Creates a new GradientFill object + # @option options [Symbol] type + # @option options [Float] degree + # @option options [Float] left + # @option options [Float] right + # @option options [Float] top + # @option options [Float] bottom + def initialize(options={}) + options[:type] ||= :linear + parse_options options + @stop = SimpleTypedList.new GradientStop + end + + serializable_attributes :type, :degree, :left, :right, :top, :bottom + # The type of gradient. # @note # valid options are @@ -36,22 +54,7 @@ module Axlsx # @return [SimpleTypedList] attr_reader :stop - # Creates a new GradientFill object - # @option options [Symbol] type - # @option options [Float] degree - # @option options [Float] left - # @option options [Float] right - # @option options [Float] top - # @option options [Float] bottom - def initialize(options={}) - options[:type] ||= :linear - options.each do |o| - self.send("#{o[0]}=", o[1]) if self.respond_to? o[0] - end - @stop = SimpleTypedList.new GradientStop - end - - # @see type + # @see type def type=(v) Axlsx::validate_gradient_type v; @type = v end # @see degree def degree=(v) Axlsx::validate_float v; @degree = v end @@ -69,8 +72,7 @@ module Axlsx # @return [String] def to_xml_string(str = '') str << '' @stop.each { |s| s.to_xml_string(str) } str << '' -- cgit v1.2.3