Class: OoxmlParser::SDTContent

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

Overview

Class for parsing ‘w:w:sdtContent` 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) ⇒ SDTContent

Returns a new instance of SDTContent.



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

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

Instance Attribute Details

#elementsArray <ParagraphRun, Table, ParagraphRun> (readonly)

Returns list of all elements in SDT.

Returns:



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

def elements
  @elements
end

Instance Method Details

#paragraphsArray<DocxParagraphs>

Returns list of paragraphs.

Returns:

  • (Array<DocxParagraphs>)

    list of paragraphs



32
33
34
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_content.rb', line 32

def paragraphs
  @elements.select { |obj| obj.is_a?(OoxmlParser::DocxParagraph) }
end

#parse(node) ⇒ SDTContent

Parse SDTContent object

Parameters:

  • node (Nokogiri::XML:Element)

    node to parse

Returns:



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_content.rb', line 17

def parse(node)
  node.xpath('*').each do |node_child|
    case node_child.name
    when 'p'
      @elements << DocxParagraph.new(parent: self).parse(node_child)
    when 'r'
      @elements << ParagraphRun.new(parent: self).parse(node_child)
    when 'tbl'
      @elements << Table.new(parent: self).parse(node_child)
    end
  end
  self
end

#runsArray<ParagraphRun>

Returns list of runs.

Returns:



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

def runs
  @elements.select { |obj| obj.is_a?(OoxmlParser::ParagraphRun) }
end

#tablesArray<Table>

Returns list of tables.

Returns:

  • (Array<Table>)

    list of tables



42
43
44
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_content.rb', line 42

def tables
  @elements.select { |obj| obj.is_a?(OoxmlParser::Table) }
end