Class: OoxmlParser::DocxShape

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

Overview

Class for parsing ‘sp`, `wsp` tags

Direct Known Subclasses

ConnectionShape

Instance Attribute Summary collapse

Attributes inherited from OOXMLDocumentObject

#parent

Instance Method Summary collapse

Methods inherited from OOXMLDocumentObject

#==, #boolean_attribute_value, #parse_xml

Methods included from OoxmlObjectAttributeHelper

#attribute_enabled?, #option_enabled?

Methods included from OoxmlDocumentObjectHelper

#to_hash

Constructor Details

#initialize(parent: nil) ⇒ DocxShape

Returns a new instance of DocxShape.



18
19
20
21
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape.rb', line 18

def initialize(parent: nil)
  @locks_text = true
  super
end

Instance Attribute Details

#body_propertiesObject

Returns the value of attribute body_properties.



12
13
14
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape.rb', line 12

def body_properties
  @body_properties
end

#locks_textTrue, False (readonly)

Returns Specifies if text in shape is locked when sheet is protected.

Returns:

  • (True, False)

    Specifies if text in shape is locked when sheet is protected



14
15
16
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape.rb', line 14

def locks_text
  @locks_text
end

#non_visual_propertiesObject

Returns the value of attribute non_visual_properties.



12
13
14
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape.rb', line 12

def non_visual_properties
  @non_visual_properties
end

#propertiesObject Also known as: shape_properties

Returns the value of attribute properties.



12
13
14
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape.rb', line 12

def properties
  @properties
end

#styleObject

Returns the value of attribute style.



12
13
14
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape.rb', line 12

def style
  @style
end

#text_bodyObject

Returns the value of attribute text_body.



12
13
14
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape.rb', line 12

def text_body
  @text_body
end

Instance Method Details

#parse(node) ⇒ DocxShape

Parse DocxShape object

Parameters:

  • node (Nokogiri::XML:Element)

    node to parse

Returns:



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/graphic/shape/docx_shape.rb', line 36

def parse(node)
  node.attributes.each do |key, value|
    case key
    when 'fLocksText'
      @locks_text = attribute_enabled?(value)
    end
  end

  node.xpath('*').each do |node_child|
    case node_child.name
    when 'nvSpPr'
      @non_visual_properties = NonVisualShapeProperties.new(parent: self).parse(node_child)
    when 'spPr'
      @properties = DocxShapeProperties.new(parent: self).parse(node_child)
    when 'style'
      @style = ShapeStyle.new(parent: self).parse(node_child)
    when 'txbx'
      @text_body = OOXMLTextBox.new(parent: self).parse(node_child)
    when 'txBody'
      @text_body = TextBody.new(parent: self).parse(node_child)
    when 'bodyPr'
      @body_properties = OOXMLShapeBodyProperties.new(parent: self).parse(node_child)
    end
  end
  self
end

#with_data?True, false

Returns if structure contain any user data.

Returns:

  • (True, false)

    if structure contain any user data



24
25
26
27
28
29
30
31
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape.rb', line 24

def with_data?
  return true if @text_body.nil?
  return true if @text_body.paragraphs.length > 1
  return true unless @text_body.paragraphs.first.runs.empty?
  return true if properties.preset_geometry

  false
end