Sha256: 857bf500d4737230744e3df4ef604b6f9759d9bd868271cbfd6844d3fea411c3

Contents?: true

Size: 1.77 KB

Versions: 1

Compression:

Stored size: 1.77 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(File.open(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

1 entries across 1 versions & 1 rubygems

Version Path
ooxml_parser-0.30.0 lib/ooxml_parser/docx_parser/document_structure/numbering.rb