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

#initialize(options = {}) ⇒ Color

Creates a new Color object

Parameters:

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

    a customizable set of options

Options Hash (options):

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


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

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

#autoBoolean

Determines if the color is system color dependant

Returns:

  • (Boolean)


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

def auto
  @auto
end

#rgbString

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)


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

def rgb
  @rgb
end

#tintFloat

Note:

valid values are between -1.0 and 1.0

The tint value.

Returns:

  • (Float)


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

def tint
  @tint
end

Instance Method Details

#to_xml_string(str = '') ⇒ String

Serializes the object

Parameters:

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

Returns:

  • (String)


67
68
69
70
71
72
73
# File 'lib/axlsx/stylesheet/color.rb', line 67

def to_xml_string(str = '')
  str << "<color "
  self.instance_values.each do |key, value|
    str << key.to_s << '="' << value.to_s << '" '
  end
  str << "/>"
end