Class: OoxmlParser::DocxParagraphRun

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

Instance Attribute Summary collapse

Attributes inherited from OOXMLDocumentObject

#parent

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DocxParagraphRunHelpers

#parse_properties

Methods inherited from OOXMLDocumentObject

add_to_xmls_stack, copy_file_and_rename_to_zip, current_xml, dir, encrypted_file?, get_link_from_rels, unzip_file, #with_data?

Methods included from OoxmlDocumentObjectHelper

#to_hash

Constructor Details

#initializeDocxParagraphRun

Returns a new instance of DocxParagraphRun.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 23

def initialize
  @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
end

Instance Attribute Details

#alternate_contentObject

Returns the value of attribute alternate_content.



11
12
13
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 11

def alternate_content
  @alternate_content
end

#background_colorObject

Returns the value of attribute background_color.



11
12
13
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 11

def background_color
  @background_color
end

#breakObject

Returns the value of attribute break.



11
12
13
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 11

def break
  @break
end

#capsObject

Returns the value of attribute caps.



11
12
13
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 11

def caps
  @caps
end

#commentsObject

Returns the value of attribute comments.



11
12
13
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 11

def comments
  @comments
end

#drawingsObject

Returns the value of attribute drawings.



11
12
13
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 11

def drawings
  @drawings
end

#effectObject

Returns the value of attribute effect.



11
12
13
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 11

def effect
  @effect
end

#emObject

Returns the value of attribute em.



11
12
13
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 11

def em
  @em
end

#endnoteObject

Returns the value of attribute endnote.



11
12
13
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 11

def endnote
  @endnote
end

#fld_charObject

Returns the value of attribute fld_char.



11
12
13
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 11

def fld_char
  @fld_char
end

#fontObject

Returns the value of attribute font.



11
12
13
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 11

def font
  @font
end

#font_colorObject

Returns the value of attribute font_color.



11
12
13
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 11

def font_color
  @font_color
end

#font_styleObject

Returns the value of attribute font_style.



11
12
13
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 11

def font_style
  @font_style
end

#footnoteObject

Returns the value of attribute footnote.



11
12
13
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 11

def footnote
  @footnote
end

#highlightObject

Returns the value of attribute highlight.



11
12
13
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 11

def highlight
  @highlight
end

#instructionString

Returns:

  • (String)

    type of instruction used for upper level of run



17
18
19
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 17

def instruction
  @instruction
end

Returns the value of attribute link.



11
12
13
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 11

def link
  @link
end

#numberObject

Returns the value of attribute number.



11
12
13
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 11

def number
  @number
end

#objectRunObject

Returns object of run.

Returns:



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

def object
  @object
end

#page_numberObject

Returns the value of attribute page_number.



11
12
13
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 11

def page_number
  @page_number
end

#positionObject

Returns the value of attribute position.



11
12
13
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 11

def position
  @position
end

#run_propertiesRunProperties

Returns properties of run.

Returns:



19
20
21
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 19

def run_properties
  @run_properties
end

#shapeObject

Returns the value of attribute shape.



11
12
13
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 11

def shape
  @shape
end

#sizeObject

Returns the value of attribute size.



11
12
13
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 11

def size
  @size
end

#spacingObject

Returns the value of attribute spacing.



11
12
13
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 11

def spacing
  @spacing
end

#styleObject

Returns the value of attribute style.



11
12
13
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 11

def style
  @style
end

#textObject

Returns the value of attribute text.



11
12
13
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 11

def text
  @text
end

#text_fillObject

Returns the value of attribute text_fill.



11
12
13
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 11

def text_fill
  @text_fill
end

#text_outlineObject

Returns the value of attribute text_outline.



11
12
13
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 11

def text_outline
  @text_outline
end

#touchObject

Returns the value of attribute touch.



11
12
13
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 11

def touch
  @touch
end

#vertical_alignObject

Returns the value of attribute vertical_align.



11
12
13
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 11

def vertical_align
  @vertical_align
end

#wObject

Returns the value of attribute w.



11
12
13
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 11

def w
  @w
end

Class Method Details

.parse_font_by_theme(theme) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 119

def self.parse_font_by_theme(theme)
  doc = Nokogiri::XML(File.open("#{OOXMLDocumentObject.path_to_folder}/#{OOXMLDocumentObject.root_subfolder}/theme/theme1.xml"))
  doc.search('//a:fontScheme').each do |font_scheme|
    if theme.include?('major')
      font_scheme.xpath('a:majorFont').each do |major_font|
        major_font.xpath('a:latin').each do |latin|
          return latin.attribute('typeface').value
        end
      end
    elsif theme.include?('minor')
      font_scheme.xpath('a:minorFont').each do |minor_font|
        minor_font.xpath('a:latin').each do |latin|
          return latin.attribute('typeface').value
        end
      end
    end
  end
end

Instance Method Details

#==(other) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 51

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

#drawingObject



46
47
48
49
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 46

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

#initialize_copy(source) ⇒ Object



40
41
42
43
44
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 40

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

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



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb', line 61

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, DocumentStructure.default_run_style)
      @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)
        when 'oval'
          @shape = Shape.new(parent: self).parse(pict_node_child, :oval)
        end
      end
    when 'object'
      @object = RunObject.new(parent: self).parse(node_child)
    end
  end
  @number = char_number
end