diff options
| author | Randy Morgan <[email protected]> | 2012-04-21 13:58:27 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-04-21 13:58:27 +0900 |
| commit | 050f4cfac1b3a52da16b98f3a494083f0de5348f (patch) | |
| tree | 889e7217fe7a731be6f3588e4e179d3d73d349cd /lib/axlsx/workbook/worksheet/icon_set.rb | |
| parent | c84e62cb7a91fefae0457baabbd9b2f3bef3259e (diff) | |
| download | caxlsx-050f4cfac1b3a52da16b98f3a494083f0de5348f.tar.gz caxlsx-050f4cfac1b3a52da16b98f3a494083f0de5348f.zip | |
adding in icon set and MOAR examples for conditional formatting.
Diffstat (limited to 'lib/axlsx/workbook/worksheet/icon_set.rb')
| -rw-r--r-- | lib/axlsx/workbook/worksheet/icon_set.rb | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/lib/axlsx/workbook/worksheet/icon_set.rb b/lib/axlsx/workbook/worksheet/icon_set.rb new file mode 100644 index 00000000..7ec94088 --- /dev/null +++ b/lib/axlsx/workbook/worksheet/icon_set.rb @@ -0,0 +1,81 @@ +module Axlsx + # Conditional Format Rule icon sets + # Describes an icon set conditional formatting rule. + + # @note The recommended way to manage these rules is via Worksheet#add_conditional_formatting + # @see Worksheet#add_conditional_formatting + # @see ConditionalFormattingRule#initialize + class IconSet + CHILD_ELEMENTS = [:value_objects] + + # The icon set to display. + # Allowed values are: 3Arrows, 3ArrowsGray, 3Flags, 3TrafficLights1, 3TrafficLights2, 3Signs, 3Symbols, 3Symbols2, 4Arrows, 4ArrowsGray, 4RedToBlack, 4Rating, 4TrafficLights, 5Arrows, 5ArrowsGray, 5Rating, 5Quarters + # The default value is 3TrafficLights1 + # @return [String] + attr_reader :iconSet + + # Indicates whether the thresholds indicate percentile values, instead of number values. + # The default falue is true + # @return [Boolean] + attr_reader :percent + + # If true, reverses the default order of the icons in this icon set.maxLength attribute + # The default value is false + # @return [Boolean] + attr_reader :reverse + + # Indicates whether to show the values of the cells on which this data bar is applied. + # The default value is true + # @return [Boolean] + attr_reader :showValue + + # Creates a new icon set object + # @option options [String] iconSet + # @option options [Boolean] reverse + # @option options [Boolean] percent + # @option options [Boolean] showValue + def initialize(options = {}) + @percent = @showValue = true + @reverse = false + @iconSet = "3TrafficLights1" + 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 iconSet + def iconSet=(v); Axlsx::validate_icon_set(v); @iconSet = v end + + # @see showValue + def showValue=(v); Axlsx.validate_boolean(v); @showValue = v end + + # @see percent + def percent=(v); Axlsx.validate_boolean(v); @percent = v end + + # @see reverse + def reverse=(v); Axlsx.validate_boolean(v); @reverse = v end + + # Serialize this object to an xml string + # @param [String] str + # @return [String] + def to_xml_string(str="") + str << '<iconSet ' + str << instance_values.map { |key, value| '' << key << '="' << value.to_s << '"' unless CHILD_ELEMENTS.include?(key.to_sym) }.join(' ') + str << '>' + @value_objects.each { |cfvo| cfvo.to_xml_string(str) } + str << '</iconSet>' + end + + private + + # Initalize the simple typed list of value objects + # I am keeping this private for now as I am not sure what impact changes to the required two cfvo objects will do. + def initialize_value_objects + @value_objects = SimpleTypedList.new Cfvo + @value_objects.concat [Cfvo.new(:type => :min, :val => 0), Cfvo.new(:type => :max, :val => 0)] + @value_objects.lock + end + end +end |
