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.37.1 lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.37.0 lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.36.1 lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.36.0 lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.35.0 lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.34.2 lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.34.1 lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.34.0 lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.33.0 lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.32.0 lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.31.0 lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.30.0 lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.29.0 lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.28.0 lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.27.0 lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.26.0 lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.25.0 lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.24.0 lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.23.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb
ooxml_parser-0.22.0 lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb