From 081c3761ec9100c19a4f9c6c8949c35c10aba29b Mon Sep 17 00:00:00 2001 From: Randy Morgan Date: Sun, 14 Oct 2012 10:47:53 +0900 Subject: Refactored DataBar to use serializable attributes and options parser --- lib/axlsx/workbook/worksheet/data_bar.rb | 37 +++++++++++++++++--------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/lib/axlsx/workbook/worksheet/data_bar.rb b/lib/axlsx/workbook/worksheet/data_bar.rb index 66a02adf..bca24bf7 100644 --- a/lib/axlsx/workbook/worksheet/data_bar.rb +++ b/lib/axlsx/workbook/worksheet/data_bar.rb @@ -7,6 +7,25 @@ module Axlsx # @see ConditionalFormattingRule#initialize class DataBar + include Axlsx::OptionsParser + include Axlsx::SerializedAttributes + + # Creates a new data bar conditional formatting object + # @option options [Integer] minLength + # @option options [Integer] maxLength + # @option options [Boolean] showValue + # @option options [String] color - the rbg value used to color the bars + def initialize(options = {}) + @minLength = 10 + @maxLength = 90 + @showValue = true + initialize_value_objects + parse_options options + yield self if block_given? + end + + serializable_attributes :minLength, :maxLength, :showValue + # instance values that must be serialized as their own elements - e.g. not attributes. CHILD_ELEMENTS = [:value_objects, :color] @@ -40,22 +59,6 @@ module Axlsx @color ||= Color.new :rgb => "FF0000FF" end - # Creates a new data bar conditional formatting object - # @option options [Integer] minLength - # @option options [Integer] maxLength - # @option options [Boolean] showValue - # @option options [String] color - the rbg value used to color the bars - def initialize(options = {}) - @minLength = 10 - @maxLength = 90 - @showValue = true - initialize_value_objects - options.each do |o| - self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}=" - end - yield self if block_given? - end - # @see minLength def minLength=(v); Axlsx.validate_unsigned_int(v); @minLength = v end # @see maxLength @@ -77,7 +80,7 @@ module Axlsx # @return [String] def to_xml_string(str="") str << '' @value_objects.each { |cfvo| cfvo.to_xml_string(str) } self.color.to_xml_string(str) -- cgit v1.2.3