Sha256: a42a50b13ca6a12e8d3d16d3f8194aed36e61e262f6f8c3d2eb3dccc6f0750b8

Contents?: true

Size: 1.63 KB

Versions: 41

Compression:

Stored size: 1.63 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
      super(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

    # @return [String] instruction applied to paragraph
    def instruction
      parent.instruction
    end

    # @return [True, False] is page number applyed
    def page_number
      parent.page_numbering?
    end

    # @return [Hyperlink] link of run
    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

41 entries across 41 versions & 1 rubygems

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