Class: Axlsx::Color

Inherits:
Object
  • Object
show all
Defined in:
lib/axlsx/stylesheet/color.rb

Overview

The color class represents a color used for borders, fills an fonts

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Color) initialize(options = {})

Creates a new Color object

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • auto (Boolean)
  • rgb (String)
  • tint (Float)


37
38
39
40
41
42
# File 'lib/axlsx/stylesheet/color.rb', line 37

def initialize(options={})
  @rgb = "FF000000"
  options.each do |o|
    self.send("#{o[0]}=", o[1]) if self.respond_to? o[0]
  end
end

Instance Attribute Details

- (Boolean) auto

Determines if the color is system color dependant

Returns:

  • (Boolean)


6
7
8
# File 'lib/axlsx/stylesheet/color.rb', line 6

def auto
  @auto
end

- (String) rgb

Note:

rgb colors need to conform to ST_UnsignedIntHex. That basically means put ‘FF’ before you color

The color as defined in rgb terms. When assigning the rgb value the behavior is much like CSS selectors and can use shorthand versions as follows: If you provide a two character value it will be repeated for each r, g, b assignment If you provide data that is not 2 characters in length, and is less than 8 characters it will be padded with "F"

Examples:

Color.new :rgb => "FF000000"
  => #<Axlsx::Color:0x102106b68 @rgb="FF000000">
Color.new :rgb => "0A"
  => #<Axlsx::Color:0x102106b68 @rgb="FF0A0A0A">
Color.new :rgb => "00BB"
  => #<Axlsx::Color:0x102106b68 @rgb="FFFF00BB">

Returns:

  • (String)


22
23
24
# File 'lib/axlsx/stylesheet/color.rb', line 22

def rgb
  @rgb
end

- (Float) tint

Note:

valid values are between -1.0 and 1.0

The tint value.

Returns:

  • (Float)


31
32
33
# File 'lib/axlsx/stylesheet/color.rb', line 31

def tint
  @tint
end

Instance Method Details

- (String) to_xml(xml)

Serializes the color

Parameters:

  • xml (Nokogiri::XML::Builder)

    The document builder instance this objects xml will be added to.

Returns:

  • (String)


67
# File 'lib/axlsx/stylesheet/color.rb', line 67

def to_xml(xml) xml.color(self.instance_values) end