Class: OoxmlParser::Shape

Inherits:
OOXMLDocumentObject show all
Defined in:
lib/ooxml_parser/docx_parser/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

#==, #boolean_attribute_value, #parse_xml, #with_data?

Methods included from OoxmlObjectAttributeHelper

#attribute_enabled?, #option_enabled?

Methods included from OoxmlDocumentObjectHelper

#to_hash

Constructor Details

#initialize(type = nil, properties = ShapeProperties.new, elements = [], parent: nil) ⇒ Shape

Returns a new instance of Shape.



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

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

Instance Attribute Details

#elementsObject

Returns the value of attribute elements.



7
8
9
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run/shape.rb', line 7

def elements
  @elements
end

#propertiesObject

Returns the value of attribute properties.



7
8
9
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run/shape.rb', line 7

def properties
  @properties
end

#typeObject

Returns the value of attribute type.



7
8
9
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run/shape.rb', line 7

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



22
23
24
25
26
27
28
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/shape.rb', line 22

def parse(node, type)
  @type = type
  node.attributes.each do |key, value|
    case key
    when 'fillcolor'
      @properties.fill_color = Color.new(parent: self)
                                    .parse_hex_string(value_to_hex(value))
    when 'strokecolor'
      @properties.stroke.color = Color.new(parent: self)
                                      .parse_hex_string(value_to_hex(value))
    when 'strokeweight'
      @properties.stroke.weight = value.value
    when 'style'
      parse_style(value.value)
    end
  end
  node.xpath('*').each do |node_child|
    case node_child.name
    when 'textbox'
      @elements = TextBox.new(parent: parent).parse_list(node_child)
    end
  end
  self
end