Sha256: 870655763253fb6deab443e681de47d194dbaa2773c87479a6cb8438a8866ebe

Contents?: true

Size: 1.08 KB

Versions: 8

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

require_relative 'styles/document_defaults'
module OoxmlParser
  # Class for parsing `styles.xml` file
  class Styles < OOXMLDocumentObject
    # @return [DocumentDefaults] defaults of document
    attr_accessor :document_defaults
    # @return [Array<DocumentStyle>] array of document styles
    attr_reader :styles

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

    # Parse styles data
    # @return [Styles] result of parsing
    def parse
      doc = parse_xml("#{root_object.unpacked_folder}word/styles.xml")
      doc.xpath('w:styles/*').each do |node_child|
        case node_child.name
        when 'docDefaults'
          @document_defaults = DocumentDefaults.new(parent: self).parse(node_child)
        when 'style'
          @styles << DocumentStyle.new(parent: self).parse(node_child)
        end
      end
      self
    end

    # @param [Symbol] type of style to get
    # @return [DocumentStyle] default document style
    def default_style(type)
      styles.find { |style| style.type == type && style.default }
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ooxml_parser-0.37.1 lib/ooxml_parser/docx_parser/document_structure/styles.rb
ooxml_parser-0.37.0 lib/ooxml_parser/docx_parser/document_structure/styles.rb
ooxml_parser-0.36.1 lib/ooxml_parser/docx_parser/document_structure/styles.rb
ooxml_parser-0.36.0 lib/ooxml_parser/docx_parser/document_structure/styles.rb
ooxml_parser-0.35.0 lib/ooxml_parser/docx_parser/document_structure/styles.rb
ooxml_parser-0.34.2 lib/ooxml_parser/docx_parser/document_structure/styles.rb
ooxml_parser-0.34.1 lib/ooxml_parser/docx_parser/document_structure/styles.rb
ooxml_parser-0.34.0 lib/ooxml_parser/docx_parser/document_structure/styles.rb