Sha256: e29c062333f60f189224ce5833b88fc05908808b7a90a10a5b838abdef614b23

Contents?: true

Size: 1.76 KB

Versions: 11

Compression:

Stored size: 1.76 KB

Contents

# frozen_string_literal: true

require_relative 'numbering/abstract_numbering'
require_relative 'numbering/numbering_definition'

module OoxmlParser
  # Class for data of Numbering
  class Numbering < OOXMLDocumentObject
    # @return [Array, AbstractNumbering] abstract numbering list
    attr_accessor :abstract_numbering_list
    # @return [Array, NumberingDefinition] numbering definition list
    attr_accessor :numbering_definition_list

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

    # Get properties by number id
    # @param num_id [Integer] index of number id
    # @return [nil, AbstractNumbering] result of search
    def properties_by_num_id(num_id)
      abstract_num_id = nil
      @numbering_definition_list.each do |num_def|
        next unless num_id == num_def.id

        abstract_num_id = num_def.abstract_numbering_id.value
        break
      end
      return nil if abstract_num_id.nil?

      @abstract_numbering_list.each do |abstract_num_item|
        return abstract_num_item if abstract_num_id == abstract_num_item.id
      end
    end

    # Parse Numbering data
    # @return [Numbering] result of parse
    def parse
      numbering_xml = "#{root_object.unpacked_folder}word/numbering.xml"
      return nil unless File.exist?(numbering_xml)

      node = parse_xml(numbering_xml)
      node.xpath('w:numbering/*').each do |numbering_child_node|
        case numbering_child_node.name
        when 'abstractNum'
          @abstract_numbering_list << AbstractNumbering.new(parent: self).parse(numbering_child_node)
        when 'num'
          @numbering_definition_list << NumberingDefinition.new(parent: self).parse(numbering_child_node)
        end
      end
      self
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
ooxml_parser-0.37.1 lib/ooxml_parser/docx_parser/document_structure/numbering.rb
ooxml_parser-0.37.0 lib/ooxml_parser/docx_parser/document_structure/numbering.rb
ooxml_parser-0.36.1 lib/ooxml_parser/docx_parser/document_structure/numbering.rb
ooxml_parser-0.36.0 lib/ooxml_parser/docx_parser/document_structure/numbering.rb
ooxml_parser-0.35.0 lib/ooxml_parser/docx_parser/document_structure/numbering.rb
ooxml_parser-0.34.2 lib/ooxml_parser/docx_parser/document_structure/numbering.rb
ooxml_parser-0.34.1 lib/ooxml_parser/docx_parser/document_structure/numbering.rb
ooxml_parser-0.34.0 lib/ooxml_parser/docx_parser/document_structure/numbering.rb
ooxml_parser-0.33.0 lib/ooxml_parser/docx_parser/document_structure/numbering.rb
ooxml_parser-0.32.0 lib/ooxml_parser/docx_parser/document_structure/numbering.rb
ooxml_parser-0.31.0 lib/ooxml_parser/docx_parser/document_structure/numbering.rb