Sha256: 1c8aa0c6c5d63fe105fc3b75056c120dee404c192a5db76a9c54d2ed6aa92351

Contents?: true

Size: 1.48 KB

Versions: 3

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

require_relative 'paragraph_run/run_properties'
require_relative 'paragraph_run/text'
module OoxmlParser
  # Class for parsing `r` tags
  class ParagraphRun < OOXMLDocumentObject
    attr_accessor :properties, :text
    # @return [Text] text of run
    attr_reader :t
    # @return [Tab] tab of paragraph
    attr_reader :tab

    def initialize(properties = RunProperties.new, text = '', parent: nil)
      @properties = properties
      @text = text
      @parent = parent
    end

    # Parse ParagraphRun object
    # @param node [Nokogiri::XML:Element] node to parse
    # @return [ParagraphRun] result of parsing
    def parse(node)
      node.xpath('*').each do |node_child|
        case node_child.name
        when 'rPr'
          @properties = RunProperties.new(parent: self).parse(node_child)
        when 't'
          @t = Text.new(parent: self).parse(node_child)
          @text = t.text
        when 'tab'
          @tab = Tab.new(parent: self).parse(node_child)
        end
      end
      self
    end

    # @return [True, False] is current run empty
    def empty?
      text.empty?
    end

    def instruction
      parent.instruction
    end

    def page_number
      parent.page_numbering?
    end

    def link
      parent.parent.hyperlink
    end

    extend Gem::Deprecate
    deprecate :instruction, 'parent.instruction', 2020, 1
    deprecate :page_number, 'parent.page_numbering?', 2020, 1
    deprecate :link, 'parent.parent.hyperlink', 2020, 1
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ooxml_parser-0.6.0 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run.rb
ooxml_parser-0.5.1 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run.rb
ooxml_parser-0.5.0 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run.rb