Sha256: 9dc3efd6417fa341022266ba8fa93aadb66dd046f51dd6f724d85e77fa3d31be

Contents?: true

Size: 1.28 KB

Versions: 25

Compression:

Stored size: 1.28 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)
      @content_types_list = []
      super
    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

    # Get content definition by type
    # @param [String] type of definition
    # @return [Object] resulting objects
    def by_type(type)
      @content_types_list.select { |item| item.content_type == type }
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
ooxml_parser-0.29.0 lib/ooxml_parser/common_parser/common_data/content_types.rb
ooxml_parser-0.28.0 lib/ooxml_parser/common_parser/common_data/content_types.rb
ooxml_parser-0.27.0 lib/ooxml_parser/common_parser/common_data/content_types.rb
ooxml_parser-0.26.0 lib/ooxml_parser/common_parser/common_data/content_types.rb
ooxml_parser-0.25.0 lib/ooxml_parser/common_parser/common_data/content_types.rb
ooxml_parser-0.24.0 lib/ooxml_parser/common_parser/common_data/content_types.rb
ooxml_parser-0.23.0 lib/ooxml_parser/common_parser/common_data/content_types.rb
ooxml_parser-0.22.0 lib/ooxml_parser/common_parser/common_data/content_types.rb
ooxml_parser-0.21.0 lib/ooxml_parser/common_parser/common_data/content_types.rb
ooxml_parser-0.20.0 lib/ooxml_parser/common_parser/common_data/content_types.rb
ooxml_parser-0.19.0 lib/ooxml_parser/common_parser/common_data/content_types.rb
ooxml_parser-0.18.1 lib/ooxml_parser/common_parser/common_data/content_types.rb
ooxml_parser-0.18.0 lib/ooxml_parser/common_parser/common_data/content_types.rb
ooxml_parser-0.17.0 lib/ooxml_parser/common_parser/common_data/content_types.rb
ooxml_parser-0.16.0 lib/ooxml_parser/common_parser/common_data/content_types.rb
ooxml_parser-0.15.0 lib/ooxml_parser/common_parser/common_data/content_types.rb
ooxml_parser-0.14.2 lib/ooxml_parser/common_parser/common_data/content_types.rb
ooxml_parser-0.14.1-mingw32 lib/ooxml_parser/common_parser/common_data/content_types.rb
ooxml_parser-0.14.1 lib/ooxml_parser/common_parser/common_data/content_types.rb
ooxml_parser-0.14.0 lib/ooxml_parser/common_parser/common_data/content_types.rb