Sha256: 4e9d1085745363bc0d9cd7c4ea9ab56c69cf7ca66fdcaf2c306f6e44ecd2af67

Contents?: true

Size: 1.26 KB

Versions: 40

Compression:

Stored size: 1.26 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 = []
      super
    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

40 entries across 40 versions & 1 rubygems

Version Path
ooxml_parser-0.21.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.20.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.19.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.18.1 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.18.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.17.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.16.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.15.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.14.2 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.14.1-mingw32 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.14.1 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.14.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.13.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.12.2 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.12.1 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.12.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.11.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.10.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.9.1 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.9.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb