Class: Axlsx::ColorScale

Inherits:
Object
  • Object
show all
Defined in:
lib/axlsx/workbook/worksheet/color_scale.rb

Overview

Note:

The recommended way to manage these rules is via Worksheet#add_conditional_formatting

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ ColorScale

creates a new ColorScale object. This method will yield it self so you can alter the properites of the defauls conditional formating value object (cfvo and colors Two value objects and two colors are created on initialization and cannot be deleted.

Yields:

  • (_self)

Yield Parameters:

See Also:



25
26
27
28
29
# File 'lib/axlsx/workbook/worksheet/color_scale.rb', line 25

def initialize
  initialize_value_objects
  initialize_colors
  yield self if block_given?
end

Instance Attribute Details

#colorsSimpleTypedList (readonly)

A simple types list of colors

See Also:



18
19
20
# File 'lib/axlsx/workbook/worksheet/color_scale.rb', line 18

def colors
  @colors
end

#value_objectsSimpleTypedList (readonly)

A simple typed list of cfvos

See Also:



13
14
15
# File 'lib/axlsx/workbook/worksheet/color_scale.rb', line 13

def value_objects
  @value_objects
end

Instance Method Details

#add(options = {}) ⇒ Hash

adds a new cfvo / color pair to the color scale and returns a hash containing a reference to the newly created cfvo and color objects so you can alter the default properties.



34
35
36
37
38
# File 'lib/axlsx/workbook/worksheet/color_scale.rb', line 34

def add(options={})
  @value_objects << Cfvo.new(:type => options[:type] || :min, :val => options[:val] || 0)
  @colors << Color.new(:rgb => options[:color] || "FF000000")
  {:cfvo => @value_objects.last, :color => @colors.last}
end

#delete_at(index = 2) ⇒ Object

Note:

you cannot remove the first two cfvo and color pairs

removes the cfvo and color pair at the index specified.



44
45
46
47
# File 'lib/axlsx/workbook/worksheet/color_scale.rb', line 44

def delete_at(index=2)
  @value_objects.delete_at index
  @colors.delete_at index
end

#to_xml_string(str = '') ⇒ String

Serialize this color_scale object data to an xml string



52
53
54
55
56
57
# File 'lib/axlsx/workbook/worksheet/color_scale.rb', line 52

def to_xml_string(str = '')
  str << '<colorScale>'
  @value_objects.each { |cfvo| cfvo.to_xml_string(str) }
  @colors.each { |color| color.to_xml_string(str) }
  str << '</colorScale>'
end