Class: OoxmlParser::ContentTypes

Inherits:
OOXMLDocumentObject show all
Defined in:
lib/ooxml_parser/common_parser/common_data/content_types.rb

Overview

Class for data from ‘[Content_Types].xml` file

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) ⇒ ContentTypes

Returns a new instance of ContentTypes.



11
12
13
14
# File 'lib/ooxml_parser/common_parser/common_data/content_types.rb', line 11

def initialize(parent: nil)
  @content_types_list = []
  super
end

Instance Attribute Details

#content_types_listArray

Returns list of content types.

Returns:

  • (Array)

    list of content types



9
10
11
# File 'lib/ooxml_parser/common_parser/common_data/content_types.rb', line 9

def content_types_list
  @content_types_list
end

Instance Method Details

#[](key) ⇒ Array

Returns accessor.

Returns:

  • (Array)

    accessor



17
18
19
# File 'lib/ooxml_parser/common_parser/common_data/content_types.rb', line 17

def [](key)
  @content_types_list[key]
end

#by_type(type) ⇒ Object

Get content definition by type

Parameters:

  • type (String)

    of definition

Returns:

  • (Object)

    resulting objects



41
42
43
# File 'lib/ooxml_parser/common_parser/common_data/content_types.rb', line 41

def by_type(type)
  @content_types_list.select { |item| item.content_type == type }
end

#parseContentTypes

Parse ContentTypes object

Returns:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ooxml_parser/common_parser/common_data/content_types.rb', line 23

def parse
  doc = parse_xml("#{root_object.unpacked_folder}/[Content_Types].xml")
  node = doc.xpath('*').first

  node.xpath('*').each do |node_child|
    case node_child.name
    when 'Default'
      @content_types_list << ContentTypeDefault.new(parent: self).parse(node_child)
    when 'Override'
      @content_types_list << ContentTypeOverride.new(parent: self).parse(node_child)
    end
  end
  self
end