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, #serialized_tag

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)


15
16
17
18
19
# File 'lib/axlsx/stylesheet/gradient_fill.rb', line 15

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

Instance Attribute Details

#bottomFloat

Percentage format bottom

Returns:

  • (Float)


49
50
51
# File 'lib/axlsx/stylesheet/gradient_fill.rb', line 49

def bottom
  @bottom
end

#degreeFloat

Angle of the linear gradient

Returns:

  • (Float)


33
34
35
# File 'lib/axlsx/stylesheet/gradient_fill.rb', line 33

def degree
  @degree
end

#leftFloat

Percentage format left

Returns:

  • (Float)


37
38
39
# File 'lib/axlsx/stylesheet/gradient_fill.rb', line 37

def left
  @left
end

#rightFloat

Percentage format right

Returns:

  • (Float)


41
42
43
# File 'lib/axlsx/stylesheet/gradient_fill.rb', line 41

def right
  @right
end

#stopSimpleTypedList (readonly)

Collection of stop objects

Returns:

  • (SimpleTypedList)


53
54
55
# File 'lib/axlsx/stylesheet/gradient_fill.rb', line 53

def stop
  @stop
end

#topFloat

Percentage format top

Returns:

  • (Float)


45
46
47
# File 'lib/axlsx/stylesheet/gradient_fill.rb', line 45

def top
  @top
end

#typeSymbol

Note:

valid options are :linear :path

The type of gradient.

Returns:

  • (Symbol)


29
30
31
# File 'lib/axlsx/stylesheet/gradient_fill.rb', line 29

def type
  @type
end

Instance Method Details

#to_xml_string(str = '') ⇒ String

Serializes the object

Parameters:

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

Returns:

  • (String)


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

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



86
87
88
# File 'lib/axlsx/stylesheet/gradient_fill.rb', line 86

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