Class: OoxmlParser::DocxDrawing

Inherits:
OOXMLDocumentObject show all
Defined in:
lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/docx_drawing.rb

Overview

Class for parsing ‘graphic` tags

Instance Attribute Summary collapse

Attributes inherited from OOXMLDocumentObject

#parent

Instance Method Summary collapse

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

#initialize(properties = DocxDrawingProperties.new, parent: nil) ⇒ DocxDrawing

Returns a new instance of DocxDrawing.



15
16
17
18
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/docx_drawing.rb', line 15

def initialize(properties = DocxDrawingProperties.new, parent: nil)
  @properties = properties
  @parent = parent
end

Instance Attribute Details

#doc_propertiesDocProperties

Returns doc properties.

Returns:



11
12
13
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/docx_drawing.rb', line 11

def doc_properties
  @doc_properties
end

#graphicObject Also known as: picture

Returns the value of attribute graphic.



9
10
11
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/docx_drawing.rb', line 9

def graphic
  @graphic
end

#propertiesObject

Returns the value of attribute properties.



9
10
11
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/docx_drawing.rb', line 9

def properties
  @properties
end

#typeObject

Returns the value of attribute type.



9
10
11
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/docx_drawing.rb', line 9

def type
  @type
end

Instance Method Details

#parse(node) ⇒ DocxDrawing

Parse DocxDrawing

Parameters:

  • node (Nokogiri::XML:Node)

    with NumberingProperties

Returns:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/docx_drawing.rb', line 23

def parse(node)
  node.xpath('*').each do |node_child|
    case node_child.name
    when 'anchor'
      @type = :flow
    when 'inline'
      @type = :inline
    end
    @properties.distance_from_text = DocxDrawingDistanceFromText.new(parent: self).parse(node_child)
    @properties.wrap = DocxWrapDrawing.new(parent: self).parse(node_child)
    node_child.attributes.each do |key, value|
      case key
      when 'relativeHeight'
        @properties.relative_height = value.value.to_i
      end
    end
    node_child.xpath('*').each do |content_node_child|
      case content_node_child.name
      when 'simplePos'
        @properties.simple_position = OOXMLCoordinates.parse(content_node_child)
      when 'extent'
        @properties.object_size = OOXMLCoordinates.parse(content_node_child, x_attr: 'cx', y_attr: 'cy', unit: :emu)
      when 'graphic'
        @graphic = DocxGraphic.new(parent: self).parse(content_node_child)
      when 'positionV'
        @properties.vertical_position = DocxDrawingPosition.new(parent: self).parse(content_node_child)
      when 'positionH'
        @properties.horizontal_position = DocxDrawingPosition.new(parent: self).parse(content_node_child)
      when 'sizeRelH'
        @properties.size_relative_horizontal = SizeRelativeHorizontal.new(parent: self).parse(content_node_child)
      when 'sizeRelV'
        @properties.size_relative_vertical = SizeRelativeVertical.new(parent: self).parse(content_node_child)
      when 'docPr'
        @doc_properties = DocProperties.new(parent: self).parse(content_node_child)
      end
    end
  end
  self
end