Class: OoxmlParser::Shape

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

Overview

Class for parsing ‘shape`, `rect`, `oval` 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(type = nil, properties = ShapeProperties.new, elements = [], parent: nil) ⇒ Shape

Returns a new instance of Shape.



7
8
9
10
11
12
13
14
15
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape.rb', line 7

def initialize(type = nil,
               properties = ShapeProperties.new,
               elements = [],
               parent: nil)
  @type = type
  @properties = properties
  @elements = elements
  @parent = parent
end

Instance Attribute Details

#elementsObject

Returns the value of attribute elements.



5
6
7
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape.rb', line 5

def elements
  @elements
end

#propertiesObject

Returns the value of attribute properties.



5
6
7
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape.rb', line 5

def properties
  @properties
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape.rb', line 5

def type
  @type
end

Instance Method Details

#parse(node, type) ⇒ Shape

Parse Shape object

Parameters:

  • node (Nokogiri::XML:Element)

    node to parse

Returns:

  • (Shape)

    result of parsing



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape.rb', line 20

def parse(node, type)
  @type = type
  node.attribute('style').value.to_s.split(';').each do |property|
    if property.include?('margin-top')
      @properties.margins.top = property.split(':').last
    elsif property.include?('margin-left')
      @properties.margins.left = property.split(':').last
    elsif property.include?('margin-right')
      @properties.margins.right = property.split(':').last
    elsif property.include?('width')
      @properties.size.width = property.split(':').last
    elsif property.include?('height')
      @properties.size.height = property.split(':').last
    elsif property.include?('z-index')
      @properties.z_index = property.split(':').last
    elsif property.include?('position')
      @properties.position = property.split(':').last
    end
  end
  @properties.fill_color = Color.new(parent: self).parse_hex_string(node.attribute('fillcolor').value.to_s.sub('#', '').split(' ').first) unless node.attribute('fillcolor').nil?
  @properties.stroke.weight = node.attribute('strokeweight').value unless node.attribute('strokeweight').nil?
  @properties.stroke.color = Color.new(parent: self).parse_hex_string(node.attribute('strokecolor').value.to_s.sub('#', '').split(' ').first) unless node.attribute('strokecolor').nil?
  @elements = TextBox.parse_list(node.xpath('v:textbox').first, parent: self) unless node.xpath('v:textbox').first.nil?
  self
end