Class: OoxmlParser::Numbering

Inherits:
OOXMLDocumentObject show all
Defined in:
lib/ooxml_parser/docx_parser/document_structure/numbering.rb

Overview

Class for data of Numbering

Instance Attribute Summary collapse

Attributes inherited from OOXMLDocumentObject

#parent

Instance Method Summary collapse

Methods inherited from OOXMLDocumentObject

#==, #boolean_attribute_value, #parse_xml, #with_data?

Methods included from OoxmlObjectAttributeHelper

#attribute_enabled?, #option_enabled?

Methods included from OoxmlDocumentObjectHelper

#to_hash

Constructor Details

#initialize(parent: nil) ⇒ Numbering

Returns a new instance of Numbering.



14
15
16
17
18
# File 'lib/ooxml_parser/docx_parser/document_structure/numbering.rb', line 14

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

Instance Attribute Details

#abstract_numbering_listArray, AbstractNumbering

Returns abstract numbering list.

Returns:



10
11
12
# File 'lib/ooxml_parser/docx_parser/document_structure/numbering.rb', line 10

def abstract_numbering_list
  @abstract_numbering_list
end

#numbering_definition_listArray, NumberingDefinition

Returns numbering definition list.

Returns:



12
13
14
# File 'lib/ooxml_parser/docx_parser/document_structure/numbering.rb', line 12

def numbering_definition_list
  @numbering_definition_list
end

Instance Method Details

#parseNumbering

Parse Numbering data

Returns:



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ooxml_parser/docx_parser/document_structure/numbering.rb', line 40

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

#properties_by_num_id(num_id) ⇒ nil, AbstractNumbering

Get properties by number id

Parameters:

  • num_id (Integer)

    index of number id

Returns:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ooxml_parser/docx_parser/document_structure/numbering.rb', line 23

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