Class: OoxmlParser::PresentationTheme

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

Overview

Class for data for PresentationTheme

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(parent: nil) ⇒ PresentationTheme

Returns a new instance of PresentationTheme.



12
13
14
15
16
# File 'lib/ooxml_parser/pptx_parser/presentation/presentation_theme.rb', line 12

def initialize(parent: nil)
  @name = ''
  @color_scheme = {}
  super
end

Instance Attribute Details

#color_schemeObject

Returns the value of attribute color_scheme.



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

def color_scheme
  @color_scheme
end

#font_schemeFontScheme

Returns font scheme.

Returns:



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

def font_scheme
  @font_scheme
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#parse(file) ⇒ PresentationTheme

Parse PresentationTheme

Parameters:

  • file (String)

    path to file to parse

Returns:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ooxml_parser/pptx_parser/presentation/presentation_theme.rb', line 21

def parse(file)
  root_object.add_to_xmls_stack(file)
  unless File.exist?(root_object.current_xml)
    root_object.xmls_stack.pop
    return
  end
  doc = parse_xml(root_object.current_xml)

  doc.xpath('a:theme').each do |theme_node|
    @name = theme_node.attribute('name').value if theme_node.attribute('name')
    theme_node.xpath('a:themeElements/*').each do |theme_element_node|
      case theme_element_node.name
      when 'clrScheme'
        theme_element_node.xpath('*').each do |color_scheme_element|
          @color_scheme[color_scheme_element.name.to_sym] = ThemeColor.new.parse(color_scheme_element)
        end
        @color_scheme[:background1] = @color_scheme[:lt1]
        @color_scheme[:background2] = @color_scheme[:lt2]
        @color_scheme[:bg1] = @color_scheme[:lt1]
        @color_scheme[:bg2] = @color_scheme[:lt2]
        @color_scheme[:text1] = @color_scheme[:dk1]
        @color_scheme[:text2] = @color_scheme[:dk2]
        @color_scheme[:tx1] = @color_scheme[:dk1]
        @color_scheme[:tx2] = @color_scheme[:dk2]
      when 'fontScheme'
        @font_scheme = FontScheme.new(parent: self).parse(theme_element_node)
      end
    end
  end
  root_object.xmls_stack.pop
  self
end