Sha256: 6a093cc447c1ad35167fa75dccc57b9958f0e7528836113db563fd5b11337936

Contents?: true

Size: 1.36 KB

Versions: 40

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

require_relative 'paragraph/paragraph_properties'
require_relative 'paragraph/paragraph_run'
require_relative 'paragraph/text_field'
module OoxmlParser
  # Class for parsing `p` tags
  class Paragraph < OOXMLDocumentObject
    attr_accessor :properties, :runs, :text_field, :formulas
    # @return [AlternateContent] alternate content data
    attr_accessor :alternate_content

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

    alias characters runs
    alias character_style_array runs
    alias characters= runs=
    alias character_style_array= runs=

    # Parse Paragraph object
    # @param node [Nokogiri::XML:Element] node to parse
    # @return [Paragraph] result of parsing
    def parse(node)
      node.xpath('*').each do |node_child|
        case node_child.name
        when 'pPr'
          @properties = ParagraphProperties.new(parent: self).parse(node_child)
        when 'fld'
          @text_field = TextField.new(parent: self).parse(node_child)
        when 'r'
          @runs << ParagraphRun.new(parent: self).parse(node_child)
        when 'AlternateContent'
          @alternate_content = AlternateContent.new(parent: self).parse(node_child)
        end
      end
      self
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
ooxml_parser-0.37.1 lib/ooxml_parser/common_parser/common_data/paragraph.rb
ooxml_parser-0.37.0 lib/ooxml_parser/common_parser/common_data/paragraph.rb
ooxml_parser-0.36.1 lib/ooxml_parser/common_parser/common_data/paragraph.rb
ooxml_parser-0.36.0 lib/ooxml_parser/common_parser/common_data/paragraph.rb
ooxml_parser-0.35.0 lib/ooxml_parser/common_parser/common_data/paragraph.rb
ooxml_parser-0.34.2 lib/ooxml_parser/common_parser/common_data/paragraph.rb
ooxml_parser-0.34.1 lib/ooxml_parser/common_parser/common_data/paragraph.rb
ooxml_parser-0.34.0 lib/ooxml_parser/common_parser/common_data/paragraph.rb
ooxml_parser-0.33.0 lib/ooxml_parser/common_parser/common_data/paragraph.rb
ooxml_parser-0.32.0 lib/ooxml_parser/common_parser/common_data/paragraph.rb
ooxml_parser-0.31.0 lib/ooxml_parser/common_parser/common_data/paragraph.rb
ooxml_parser-0.30.0 lib/ooxml_parser/common_parser/common_data/paragraph.rb
ooxml_parser-0.29.0 lib/ooxml_parser/common_parser/common_data/paragraph.rb
ooxml_parser-0.28.0 lib/ooxml_parser/common_parser/common_data/paragraph.rb
ooxml_parser-0.27.0 lib/ooxml_parser/common_parser/common_data/paragraph.rb
ooxml_parser-0.26.0 lib/ooxml_parser/common_parser/common_data/paragraph.rb
ooxml_parser-0.25.0 lib/ooxml_parser/common_parser/common_data/paragraph.rb
ooxml_parser-0.24.0 lib/ooxml_parser/common_parser/common_data/paragraph.rb
ooxml_parser-0.23.0 lib/ooxml_parser/common_parser/common_data/paragraph.rb
ooxml_parser-0.22.0 lib/ooxml_parser/common_parser/common_data/paragraph.rb