Class: Axlsx::GradientFill

Inherits:
Object
  • Object
show all
Includes:
OptionsParser, SerializedAttributes
Defined in:
lib/axlsx/stylesheet/gradient_fill.rb

Overview

A GradientFill defines the color and positioning for gradiant cell fill.

See Also:

  • Office XML Part 1 ยง18.8.24

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SerializedAttributes

#declared_attributes, included, #serialized_attributes, #serialized_element_attributes

Methods included from OptionsParser

#parse_options

Constructor Details

#initialize(options = {}) ⇒ GradientFill

Creates a new GradientFill object

Parameters:

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

    a customizable set of options

Options Hash (options):

  • type (Symbol)
  • degree (Float)
  • left (Float)
  • right (Float)
  • top (Float)
  • bottom (Float)


17
18
19
20
21
# File 'lib/axlsx/stylesheet/gradient_fill.rb', line 17

def initialize(options={})
  options[:type] ||= :linear
  parse_options options
  @stop = SimpleTypedList.new GradientStop
end

Instance Attribute Details

#bottomFloat

Percentage format bottom

Returns:

  • (Float)


51
52
53
# File 'lib/axlsx/stylesheet/gradient_fill.rb', line 51

def bottom
  @bottom
end

#degreeFloat

Angle of the linear gradient

Returns:

  • (Float)


35
36
37
# File 'lib/axlsx/stylesheet/gradient_fill.rb', line 35

def degree
  @degree
end

#leftFloat

Percentage format left

Returns:

  • (Float)


39
40
41
# File 'lib/axlsx/stylesheet/gradient_fill.rb', line 39

def left
  @left
end

#rightFloat

Percentage format right

Returns:

  • (Float)


43
44
45
# File 'lib/axlsx/stylesheet/gradient_fill.rb', line 43

def right
  @right
end

#stopSimpleTypedList (readonly)

Collection of stop objects

Returns:

  • (SimpleTypedList)


55
56
57
# File 'lib/axlsx/stylesheet/gradient_fill.rb', line 55

def stop
  @stop
end

#topFloat

Percentage format top

Returns:

  • (Float)


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

def top
  @top
end

#typeSymbol

Note:

valid options are :linear :path

The type of gradient.

Returns:

  • (Symbol)


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

def type
  @type
end

Instance Method Details

#to_xml_string(str = '') ⇒ String

Serializes the object

Parameters:

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

Returns:

  • (String)


95
96
97
98
99
100
101
# File 'lib/axlsx/stylesheet/gradient_fill.rb', line 95

def to_xml_string(str = '')
  str << '<gradientFill '
  serialized_attributes str
  str << '>'
  @stop.each { |s| s.to_xml_string(str) }
  str << '</gradientFill>'
end

#validate_format_percentage(name, value) ⇒ Object

validates that the value provided is between 0.0 and 1.0



88
89
90
# File 'lib/axlsx/stylesheet/gradient_fill.rb', line 88

def validate_format_percentage(name, value)
  DataTypeValidator.validate name, Float, value, lambda { |arg| arg >= 0.0 && arg <= 1.0}
end