class OoxmlParser::PresentationTheme

Class for data for PresentationTheme

Attributes

color_scheme[RW]
font_scheme[RW]

@return [FontScheme] font scheme

name[RW]

Public Class Methods

new(parent: nil) click to toggle source
Calls superclass method OoxmlParser::OOXMLDocumentObject::new
# File lib/ooxml_parser/pptx_parser/presentation/presentation_theme.rb, line 12
def initialize(parent: nil)
  @name = ''
  @color_scheme = {}
  super
end

Public Instance Methods

parse(file) click to toggle source

Parse PresentationTheme @param file [String] path to file to parse @return [PresentationTheme] result of parsing

# 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