Class: OoxmlParser::DocxParagraphRun

Inherits:
OOXMLDocumentObject show all
Includes:
DocxParagraphRunHelpers
Defined in:
lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb

Overview

Class for working with DocxParagraphRun

Instance Attribute Summary collapse

Attributes inherited from OOXMLDocumentObject

#parent

Instance Method Summary collapse

Methods included from DocxParagraphRunHelpers

#background_color, #parse_properties

Methods inherited from OOXMLDocumentObject

#boolean_attribute_value, #parse_xml, #with_data?

Methods included from OoxmlObjectAttributeHelper

#attribute_enabled?, #option_enabled?

Methods included from OoxmlDocumentObjectHelper

#to_hash

Constructor Details

#initialize(parent: nil) ⇒ DocxParagraphRun

Returns a new instance of DocxParagraphRun.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 29

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

Instance Attribute Details

#alternate_contentObject

Returns the value of attribute alternate_content.



15
16
17
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 15

def alternate_content
  @alternate_content
end

#breakObject

Returns the value of attribute break.



15
16
17
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 15

def break
  @break
end

#capsObject

Returns the value of attribute caps.



15
16
17
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 15

def caps
  @caps
end

#commentsObject

Returns the value of attribute comments.



15
16
17
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 15

def comments
  @comments
end

#drawingsObject

Returns the value of attribute drawings.



15
16
17
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 15

def drawings
  @drawings
end

#effectObject

Returns the value of attribute effect.



15
16
17
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 15

def effect
  @effect
end

#emObject

Returns the value of attribute em.



15
16
17
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 15

def em
  @em
end

#endnoteObject

Returns the value of attribute endnote.



15
16
17
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 15

def endnote
  @endnote
end

#fld_charObject

Returns the value of attribute fld_char.



15
16
17
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 15

def fld_char
  @fld_char
end

#fontObject

Returns the value of attribute font.



15
16
17
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 15

def font
  @font
end

#font_colorObject

Returns the value of attribute font_color.



15
16
17
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 15

def font_color
  @font_color
end

#font_styleObject

Returns the value of attribute font_style.



15
16
17
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 15

def font_style
  @font_style
end

#footnoteObject

Returns the value of attribute footnote.



15
16
17
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 15

def footnote
  @footnote
end

#highlightObject

Returns the value of attribute highlight.



15
16
17
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 15

def highlight
  @highlight
end

#instruction_textInstructionText (readonly)

Returns text of instruction See ECMA-376, 17.16.23 instrText (Field Code).

Returns:

  • (InstructionText)

    text of instruction See ECMA-376, 17.16.23 instrText (Field Code)



21
22
23
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 21

def instruction_text
  @instruction_text
end

Returns the value of attribute link.



15
16
17
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 15

def link
  @link
end

#numberObject

Returns the value of attribute number.



15
16
17
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 15

def number
  @number
end

#objectRunObject

Returns object of run.

Returns:



25
26
27
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 25

def object
  @object
end

#page_numberObject

Returns the value of attribute page_number.



15
16
17
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 15

def page_number
  @page_number
end

#positionObject

Returns the value of attribute position.



15
16
17
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 15

def position
  @position
end

#run_propertiesRunProperties

Returns properties of run.

Returns:



23
24
25
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 23

def run_properties
  @run_properties
end

#shadeShade

Returns shade properties.

Returns:

  • (Shade)

    shade properties



27
28
29
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 27

def shade
  @shade
end

#shapeObject

Returns the value of attribute shape.



15
16
17
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 15

def shape
  @shape
end

#sizeObject

Returns the value of attribute size.



15
16
17
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 15

def size
  @size
end

#spacingObject

Returns the value of attribute spacing.



15
16
17
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 15

def spacing
  @spacing
end

#styleObject

Returns the value of attribute style.



15
16
17
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 15

def style
  @style
end

#textObject

Returns the value of attribute text.



15
16
17
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 15

def text
  @text
end

#text_fillObject

Returns the value of attribute text_fill.



15
16
17
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 15

def text_fill
  @text_fill
end

#text_outlineObject

Returns the value of attribute text_outline.



15
16
17
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 15

def text_outline
  @text_outline
end

#touchObject

Returns the value of attribute touch.



15
16
17
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 15

def touch
  @touch
end

#vertical_alignObject

Returns the value of attribute vertical_align.



15
16
17
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 15

def vertical_align
  @vertical_align
end

#wObject

Returns the value of attribute w.



15
16
17
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 15

def w
  @w
end

Instance Method Details

#==(other) ⇒ True, False

Compare this object to other

Parameters:

  • other (Object)

    any other object

Returns:

  • (True, False)

    result of comparision



77
78
79
80
81
82
83
84
85
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 77

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

#drawingArray?

Returns Drawings of Run.

Returns:

  • (Array, nil)

    Drawings of Run



57
58
59
60
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 57

def drawing
  # TODO: Rewrite all tests without this methos
  @drawings.empty? ? nil : drawings.first
end

#empty?True, False

Returns is current run empty.

Returns:

  • (True, False)

    is current run empty



63
64
65
66
67
68
69
70
71
72
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 63

def empty?
  text.empty? &&
    !alternate_content &&
    !drawing &&
    !object &&
    !shape &&
    !footnote &&
    !endnote &&
    !@break
end

#initialize_copy(source) ⇒ void

This method returns an undefined value.

Constructor for copy of object

Parameters:



50
51
52
53
54
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 50

def initialize_copy(source)
  super
  @drawings = source.drawings.clone
  @comments = source.comments.clone
end

#parse(r_tag, char_number, parent: nil) ⇒ void

This method returns an undefined value.

Parse object

Parameters:

  • r_tag (Nokogiri::XML:Node)

    node with DocxParagraphRun

  • char_number (Integer)

    number of run

  • parent (OOXMLDocumentObject) (defaults to: nil)

    parent of run



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb', line 92

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'
      @instruction_text = InstructionText.new(parent: self).parse(node_child)
      if @instruction_text.hyperlink?
        @link = @instruction_text.to_hyperlink
      elsif @instruction_text.page_number?
        @text = '*PAGE NUMBER*'
      end
    when 'fldChar'
      @field_char_object = FieldChar.new(parent: self).parse(node_child)
      @fld_char = @field_char_object.type
    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