Class: OoxmlParser::Shape
- Inherits:
-
OOXMLDocumentObject
- Object
- OOXMLDocumentObject
- OoxmlParser::Shape
- Defined in:
- lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape.rb
Constant Summary
Constants inherited from OOXMLDocumentObject
OOXMLDocumentObject::DEFAULT_DIRECTORY_FOR_MEDIA
Instance Attribute Summary collapse
-
#elements ⇒ Object
Returns the value of attribute elements.
-
#properties ⇒ Object
Returns the value of attribute properties.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(type = nil, properties = ShapeProperties.new, elements = []) ⇒ Shape
constructor
A new instance of Shape.
Methods inherited from OOXMLDocumentObject
#==, add_to_xmls_stack, copy_file_and_rename_to_zip, copy_media_file, current_xml, dir, encrypted_file?, get_link_from_rels, media_folder, option_enabled?, unzip_file
Constructor Details
#initialize(type = nil, properties = ShapeProperties.new, elements = []) ⇒ Shape
Returns a new instance of Shape.
6 7 8 9 10 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape.rb', line 6 def initialize(type = nil, properties = ShapeProperties.new, elements = []) @type = type @properties = properties @elements = elements end |
Instance Attribute Details
#elements ⇒ Object
Returns the value of attribute elements.
4 5 6 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape.rb', line 4 def elements @elements end |
#properties ⇒ Object
Returns the value of attribute properties.
4 5 6 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape.rb', line 4 def properties @properties end |
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape.rb', line 4 def type @type end |
Class Method Details
.parse(shape_node, type) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape.rb', line 12 def self.parse(shape_node, type) shape = Shape.new shape.type = type shape_node.attribute('style').value.to_s.split(';').each do |property| if property.include?('margin-top') shape.properties.margins.top = property.split(':').last elsif property.include?('margin-left') shape.properties.margins.left = property.split(':').last elsif property.include?('margin-right') shape.properties.margins.right = property.split(':').last elsif property.include?('width') shape.properties.size.width = property.split(':').last elsif property.include?('height') shape.properties.size.height = property.split(':').last elsif property.include?('z-index') shape.properties.z_index = property.split(':').last elsif property.include?('position') shape.properties.position = property.split(':').last end end shape.properties.fill_color = Color.from_int16(shape_node.attribute('fillcolor').value.to_s.sub('#', '').split(' ').first) unless shape_node.attribute('fillcolor').nil? shape.properties.stroke.weight = shape_node.attribute('strokeweight').value unless shape_node.attribute('strokeweight').nil? shape.properties.stroke.color = Color.from_int16(shape_node.attribute('strokecolor').value.to_s.sub('#', '').split(' ').first) unless shape_node.attribute('strokecolor').nil? shape.elements = TextBox.parse_list(shape_node.xpath('v:textbox').first) unless shape_node.xpath('v:textbox').first.nil? shape end |