Sha256: dbbf83118a43acdfefafde7396ae5099f3d9c017a2dfd266ea13180a6ed574a5

Contents?: true

Size: 1.27 KB

Versions: 8

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module OoxmlParser
  # Class for parsing `w:w:sdtContent` tags
  class SDTContent < OOXMLDocumentObject
    # @return [Array <ParagraphRun, Table, ParagraphRun>] list of all elements in SDT
    attr_reader :elements

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

    # Parse SDTContent object
    # @param node [Nokogiri::XML:Element] node to parse
    # @return [SDTContent] result of parsing
    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

    # @return [Array<DocxParagraphs>] list of paragraphs
    def paragraphs
      @elements.select { |obj| obj.is_a?(OoxmlParser::DocxParagraph) }
    end

    # @return [Array<ParagraphRun>] list of runs
    def runs
      @elements.select { |obj| obj.is_a?(OoxmlParser::ParagraphRun) }
    end

    # @return [Array<Table>] list of tables
    def tables
      @elements.select { |obj| obj.is_a?(OoxmlParser::Table) }
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ooxml_parser-0.8.1 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.8.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.7.2 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.7.1 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.7.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.6.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.5.1 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.5.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb