Class: OoxmlParser::GradientColor

Inherits:
Object
  • Object
show all
Defined in:
lib/ooxml_parser/common_parser/common_data/colors/presentation_fill/gradient_color.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(colors = []) ⇒ GradientColor

Returns a new instance of GradientColor.



7
8
9
# File 'lib/ooxml_parser/common_parser/common_data/colors/presentation_fill/gradient_color.rb', line 7

def initialize(colors = [])
  @gradient_stops = colors
end

Instance Attribute Details

#gradient_stopsObject

Returns the value of attribute gradient_stops.



5
6
7
# File 'lib/ooxml_parser/common_parser/common_data/colors/presentation_fill/gradient_color.rb', line 5

def gradient_stops
  @gradient_stops
end

#pathObject

Returns the value of attribute path.



5
6
7
# File 'lib/ooxml_parser/common_parser/common_data/colors/presentation_fill/gradient_color.rb', line 5

def path
  @path
end

Class Method Details

.parse(gradient_fill_node) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ooxml_parser/common_parser/common_data/colors/presentation_fill/gradient_color.rb', line 11

def self.parse(gradient_fill_node)
  gradient_color = GradientColor.new
  gradient_fill_node.xpath('*').each do |gradient_fill_node_child|
    case gradient_fill_node_child.name
    when 'gsLst'
      begin
        gradient_fill_node_child.xpath('//a:gs')
        namespace = 'a'
      rescue Nokogiri::XML::XPath::SyntaxError
        namespace = 'w14'
      end
      gradient_fill_node_child.xpath("#{namespace}:gs").each do |gradient_stop_node|
        gradient_color.gradient_stops << GradientStop.parse(gradient_stop_node)
      end
    when 'path'
      gradient_color.path = gradient_fill_node_child.attribute('path').value.to_sym
    when 'lin'
      gradient_color.path = LinearGradient.parse(gradient_fill_node_child)
    end
  end
  gradient_color
end