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:



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

def initialize
  initialize_colors
  yield self if block_given?
end

Instance Attribute Details

#colorsSimpleTypedList (readonly)

A simple types list of colors

Returns:

  • (SimpleTypedList)

See Also:



20
21
22
# File 'lib/axlsx/workbook/worksheet/color_scale.rb', line 20

def colors
  @colors
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.

Returns:

  • (Hash)

    a hash with :cfvo and :color keys referencing the newly added objects.



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

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.

Parameters:

  • index (Integer) (defaults to: 2)

    The index of the cfvo and color object to delete



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

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

Parameters:

  • str (String) (defaults to: '')

Returns:

  • (String)


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

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

#value_objectsSimpleTypedList

A simple typed list of cfvos

Returns:

  • (SimpleTypedList)

See Also:



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

def value_objects
  @value_objects ||= Cfvos.new
end