Class: OoxmlParser::ThemeColor

Inherits:
OOXMLDocumentObject show all
Defined in:
lib/ooxml_parser/pptx_parser/presentation/presentation_theme/theme_color.rb

Overview

Class for parsing ThemeColor tags

Instance Attribute Summary collapse

Attributes inherited from OOXMLDocumentObject

#parent

Instance Method Summary collapse

Methods inherited from OOXMLDocumentObject

#boolean_attribute_value, #parse_xml, #with_data?

Methods included from OoxmlObjectAttributeHelper

#attribute_enabled?, #option_enabled?

Methods included from OoxmlDocumentObjectHelper

#to_hash

Constructor Details

#initialize(type: '', color: nil, parent: nil) ⇒ ThemeColor

Returns a new instance of ThemeColor.



8
9
10
11
12
# File 'lib/ooxml_parser/pptx_parser/presentation/presentation_theme/theme_color.rb', line 8

def initialize(type: '', color: nil, parent: nil)
  @type = type
  @color = color
  super(parent: parent)
end

Instance Attribute Details

#colorObject

Returns the value of attribute color.



6
7
8
# File 'lib/ooxml_parser/pptx_parser/presentation/presentation_theme/theme_color.rb', line 6

def color
  @color
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/ooxml_parser/pptx_parser/presentation/presentation_theme/theme_color.rb', line 6

def type
  @type
end

#valueObject

Returns the value of attribute value.



6
7
8
# File 'lib/ooxml_parser/pptx_parser/presentation/presentation_theme/theme_color.rb', line 6

def value
  @value
end

Instance Method Details

#==(other) ⇒ True, False

Compare ThemeColor with other object

Parameters:

  • other (Object)

    object to compare

Returns:

  • (True, False)

    result of comparision



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ooxml_parser/pptx_parser/presentation/presentation_theme/theme_color.rb', line 17

def ==(other)
  if other.is_a?(Color)
    @color == other
  else
    all_instance_variables = instance_variables
    all_instance_variables.each do |current_attributes|
      return false unless instance_variable_get(current_attributes) == other.instance_variable_get(current_attributes)
    end
    true
  end
end

#parse(node) ⇒ ThemeColor

Parse ThemeColor

Parameters:

  • node (Nokogiri::XML::Element)

    node to parse

Returns:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ooxml_parser/pptx_parser/presentation/presentation_theme/theme_color.rb', line 32

def parse(node)
  node.xpath('*').each do |node_child|
    case node_child.name
    when 'sysClr'
      @type = :system
      @value = node_child.attribute('val').value
      @color = Color.new(parent: self).parse_hex_string(node_child.attribute('lastClr').value.to_s) unless node_child.attribute('lastClr').nil?
    when 'srgbClr'
      @type = :rgb
      @color = Color.new(parent: self).parse_hex_string(node_child.attribute('val').value.to_s)
    end
  end
  self
end