Class: OoxmlParser::FieldSimple

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

Overview

Class for parsing ‘w:fldSimple` tags

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) ⇒ FieldSimple

Returns a new instance of FieldSimple.



11
12
13
14
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/field_simple.rb', line 11

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

Instance Attribute Details

#instructionString (readonly)

Returns instruction value.

Returns:

  • (String)

    instruction value



7
8
9
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/field_simple.rb', line 7

def instruction
  @instruction
end

#runsArray<ParagraphRun> (readonly)

Returns instruction value.

Returns:



9
10
11
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/field_simple.rb', line 9

def runs
  @runs
end

Instance Method Details

#page_numbering?True, False

Returns is field simple page numbering.

Returns:

  • (True, False)

    is field simple page numbering



37
38
39
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/field_simple.rb', line 37

def page_numbering?
  instruction.include?('PAGE')
end

#parse(node) ⇒ FieldSimple

Parse FieldSimple object

Parameters:

  • node (Nokogiri::XML:Element)

    node to parse

Returns:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/field_simple.rb', line 19

def parse(node)
  node.attributes.each do |key, value|
    case key
    when 'instr'
      @instruction = value.value.to_s
    end
  end

  node.xpath('*').each do |node_child|
    case node_child.name
    when 'r'
      @runs << ParagraphRun.new(parent: self).parse(node_child)
    end
  end
  self
end