Sha256: 6e7c6fabf1d3033f872b8a7cd62091100caed3c7346caa54f96b921ec9a05ead

Contents?: true

Size: 1.07 KB

Versions: 5

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

require_relative 'content_types/content_type_default'
require_relative 'content_types/content_type_override'
module OoxmlParser
  # Class for data from `[Content_Types].xml` file
  class ContentTypes < OOXMLDocumentObject
    # @return [Array] list of content types
    attr_accessor :content_types_list

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

    # @return [Array] accessor
    def [](key)
      @content_types_list[key]
    end

    # Parse ContentTypes object
    # @return [ContentTypes] result of parsing
    def parse
      doc = Nokogiri::XML.parse(File.open("#{OOXMLDocumentObject.path_to_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
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ooxml_parser-0.8.1 lib/ooxml_parser/common_parser/common_data/content_types.rb
ooxml_parser-0.8.0 lib/ooxml_parser/common_parser/common_data/content_types.rb
ooxml_parser-0.7.2 lib/ooxml_parser/common_parser/common_data/content_types.rb
ooxml_parser-0.7.1 lib/ooxml_parser/common_parser/common_data/content_types.rb
ooxml_parser-0.7.0 lib/ooxml_parser/common_parser/common_data/content_types.rb