Class: Axlsx::Color

Inherits:
Object
  • Object
show all
Includes:
OptionsParser, SerializedAttributes
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

Methods included from SerializedAttributes

included, #serialized_attributes, #serialized_element_attributes

Methods included from OptionsParser

#parse_options

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)


13
14
15
16
# File 'lib/axlsx/stylesheet/color.rb', line 13

def initialize(options={})
  @rgb = "FF000000"
  parse_options options
end

Instance Attribute Details

#autoBoolean

Determines if the color is system color dependant

Returns:

  • (Boolean)


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

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)


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

def rgb
  @rgb
end

#tintFloat

Note:

valid values are between -1.0 and 1.0

The tint value.

Returns:

  • (Float)


47
48
49
# File 'lib/axlsx/stylesheet/color.rb', line 47

def tint
  @tint
end

Instance Method Details

#to_xml_string(str = '', tag_name = 'color') ⇒ String

Serializes the object

Parameters:

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

Returns:

  • (String)


72
73
74
75
76
# File 'lib/axlsx/stylesheet/color.rb', line 72

def to_xml_string(str = '', tag_name = 'color')
  str << "<" << tag_name << " "
  serialized_attributes str
  str << "/>"
end