class OoxmlParser::DocxParagraphRun

Class for working with DocxParagraphRun

Attributes

alternate_content[RW]
break[RW]
caps[RW]
comments[RW]
drawings[RW]
effect[RW]
em[RW]
endnote[RW]
fld_char[RW]
font[RW]
font_color[RW]
font_style[RW]
footnote[RW]
highlight[RW]
instruction[RW]

@return [String] type of instruction used for upper level of run officeopenxml.com/WPfieldInstructions.php

number[RW]
object[RW]

@return [RunObject] object of run

page_number[RW]
position[RW]
run_properties[RW]

@return [RunProperties] properties of run

shade[RW]

@return [Shade] shade properties

shape[RW]
size[RW]
spacing[RW]
style[RW]
text[RW]
text_fill[RW]
text_outline[RW]
touch[RW]
vertical_align[RW]
w[RW]

Public Class Methods

new(parent: nil) click to toggle source
Calls superclass method OoxmlParser::OOXMLDocumentObject::new
# File lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb, line 28
def initialize(parent: nil)
  @number = 0
  @font = 'Arial'
  @vertical_align = :baseline
  @size = 11
  @font_color = Color.new
  @font_style = FontStyle.new
  @text = ''
  @drawings = []
  @w = false
  @position = 0.0
  @spacing = 0.0
  @break = false
  @comments = []
  @page_number = false
  super
end

Public Instance Methods

==(other) click to toggle source

Compare this object to other @param other [Object] any other object @return [True, False] result of comparision

# File lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb, line 76
def ==(other)
  ignored_attributes = %i[@number @parent]
  all_instance_variables = instance_variables
  significan_attribues = all_instance_variables - ignored_attributes
  significan_attribues.each do |current_attributes|
    return false unless instance_variable_get(current_attributes) == other.instance_variable_get(current_attributes)
  end
  true
end
drawing() click to toggle source

@return [Array, nil] Drawings of Run

# File lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb, line 56
def drawing
  # TODO: Rewrite all tests without this methos
  @drawings.empty? ? nil : drawings.first
end
empty?() click to toggle source

@return [True, False] is current run empty

# File lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb, line 62
def empty?
  text.empty? &&
    !alternate_content &&
    !drawing &&
    !object &&
    !shape &&
    !footnote &&
    !endnote &&
    !@break
end
initialize_copy(source) click to toggle source

Constructor for copy of object @param source [DocxParagraphRun] original object @return [void]

Calls superclass method
# File lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb, line 49
def initialize_copy(source)
  super
  @drawings = source.drawings.clone
  @comments = source.comments.clone
end
parse(r_tag, char_number, parent: nil) click to toggle source

Parse object @param r_tag [Nokogiri::XML:Node] node with DocxParagraphRun @param char_number [Integer] number of run @param parent [OOXMLDocumentObject] parent of run @return [void]

# File lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb, line 91
def parse(r_tag, char_number, parent: nil)
  @parent = parent
  r_tag.xpath('*').each do |node_child|
    case node_child.name
    when 'rPr'
      parse_properties(node_child)
      @run_properties = RunProperties.new(parent: self).parse(node_child)
    when 'instrText'
      if node_child.text.include?('HYPERLINK')
        hyperlink = Hyperlink.new(node_child.text.sub('HYPERLINK ', '').split(' \\o ').first, node_child.text.sub('HYPERLINK', '').split(' \\o ').last)
        @link = hyperlink
      elsif node_child.text[/PAGE\s+\\\*/]
        @text = '*PAGE NUMBER*'
      end
    when 'fldChar'
      @fld_char = node_child.attribute('fldCharType').value.to_sym
    when 't'
      @text += node_child.text
    when 'noBreakHyphen'
      @text += '–'
    when 'tab'
      @text += "\t"
    when 'drawing'
      @drawings << DocxDrawing.new(parent: self).parse(node_child)
    when 'AlternateContent'
      @alternate_content = AlternateContent.new(parent: self).parse(node_child)
    when 'br'
      if node_child.attribute('type').nil?
        @break = :line
        @text += "\r"
      else
        case node_child.attribute('type').value
        when 'page', 'column'
          @break = node_child.attribute('type').value.to_sym
        end
      end
    when 'footnoteReference'
      @footnote = HeaderFooter.new(parent: self).parse(node_child)
    when 'endnoteReference'
      @endnote = HeaderFooter.new(parent: self).parse(node_child)
    when 'pict'
      node_child.xpath('*').each do |pict_node_child|
        case pict_node_child.name
        when 'shape'
          @shape = Shape.new(parent: self).parse(pict_node_child, :shape)
        when 'rect'
          @shape = Shape.new(parent: self).parse(pict_node_child, :rectangle)
        end
      end
    when 'object'
      @object = RunObject.new(parent: self).parse(node_child)
    end
  end
  @number = char_number
end