Class: OoxmlParser::Slide
- Inherits:
-
OOXMLDocumentObject
- Object
- OOXMLDocumentObject
- OoxmlParser::Slide
- Defined in:
- lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide.rb
Constant Summary
Constants inherited from OOXMLDocumentObject
OOXMLDocumentObject::DEFAULT_DIRECTORY_FOR_MEDIA
Instance Attribute Summary collapse
-
#alternate_content ⇒ Object
Returns the value of attribute alternate_content.
-
#background ⇒ Object
Returns the value of attribute background.
-
#elements ⇒ Object
Returns the value of attribute elements.
-
#timing ⇒ Object
Returns the value of attribute timing.
-
#transition ⇒ Object
Returns the value of attribute transition.
Class Method Summary collapse
Instance Method Summary collapse
- #content_distribute(object, slide_size) ⇒ Object
- #content_horizontal_align(object, slide_size) ⇒ Object
- #content_vertical_align(object, slide_size) ⇒ Object
- #graphic_frames ⇒ Object
-
#initialize(elements = [], background = nil) ⇒ Slide
constructor
A new instance of Slide.
- #nonempty_elements ⇒ Object
-
#transform_of_object(object) ⇒ OOXMLDocumentObject
Get transform property of object, by object type.
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(elements = [], background = nil) ⇒ Slide
Returns a new instance of Slide.
10 11 12 13 |
# File 'lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide.rb', line 10 def initialize(elements = [], background = nil) @elements = elements @background = background end |
Instance Attribute Details
#alternate_content ⇒ Object
Returns the value of attribute alternate_content.
8 9 10 |
# File 'lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide.rb', line 8 def alternate_content @alternate_content end |
#background ⇒ Object
Returns the value of attribute background.
8 9 10 |
# File 'lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide.rb', line 8 def background @background end |
#elements ⇒ Object
Returns the value of attribute elements.
8 9 10 |
# File 'lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide.rb', line 8 def elements @elements end |
#timing ⇒ Object
Returns the value of attribute timing.
8 9 10 |
# File 'lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide.rb', line 8 def timing @timing end |
#transition ⇒ Object
Returns the value of attribute transition.
8 9 10 |
# File 'lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide.rb', line 8 def transition @transition end |
Class Method Details
.parse(path_to_slide_xml) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide.rb', line 63 def self.parse() = Slide.new OOXMLDocumentObject.add_to_xmls_stack() doc = Nokogiri::XML(File.open(OOXMLDocumentObject.current_xml)) doc.xpath('//p:sld/*').each do || case .name when 'cSld' .xpath('*').each do || case .name when 'spTree' .xpath('*').each do || case .name when 'nvGrpSpPr' when 'grpSpPr' when 'sp' .elements << PresentationShape.parse().dup when 'pic' .elements << DocxPicture.parse() when 'graphicFrame' .elements << GraphicFrame.parse() when 'grpSp' .elements << ShapesGrouping.parse() end end when 'bg' .background = Background.parse() end end when 'clrMapOvr' when 'timing' .timing = Timing.parse() when 'transition' .transition = Transition.parse() when 'AlternateContent' .alternate_content = PresentationAlternateContent.parse() end end OOXMLDocumentObject.xmls_stack.pop end |
Instance Method Details
#content_distribute(object, slide_size) ⇒ Object
57 58 59 60 61 |
# File 'lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide.rb', line 57 def content_distribute(object, ) return [:horizontally, :vertically] if content_horizontal_align(object, ) == :center && content_vertical_align(object, ) == :middle return [:horizontally] if content_horizontal_align(object, ) == :center return [:vertically] if content_vertical_align(object, ) == :middle end |
#content_horizontal_align(object, slide_size) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide.rb', line 41 def content_horizontal_align(object, ) transform = transform_of_object(object) return :left if transform.offset.x == 0 return :center if ((.width / 2) - (transform.extents.x / 2)).round(1) == transform.offset.x.round(1) return :right if (.width - transform.extents.x).round(1) == transform.offset.x.round(1) :unknown end |
#content_vertical_align(object, slide_size) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide.rb', line 49 def content_vertical_align(object, ) transform = transform_of_object(object) return :top if transform.offset.y == 0 return :middle if ((.height / 2) - (transform.extents.y / 2)).round(1) == transform.offset.y.round(1) return :bottom if (.height - transform.extents.y).round(1) == transform.offset.y.round(1) :unknown end |
#graphic_frames ⇒ Object
19 20 21 |
# File 'lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide.rb', line 19 def graphic_frames @elements.select { |cur_element| cur_element.is_a?(GraphicFrame) } end |
#nonempty_elements ⇒ Object
15 16 17 |
# File 'lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide.rb', line 15 def nonempty_elements @elements.select { |cur_shape| !cur_shape.text_body.paragraphs.first.characters.empty? } end |
#transform_of_object(object) ⇒ OOXMLDocumentObject
Get transform property of object, by object type
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide.rb', line 26 def transform_of_object(object) case object when :image return elements.find { |e| e.is_a? Picture }.properties.transform when :chart return elements.find { |e| e.is_a? GraphicFrame }.transform when :table return elements.find { |e| e.is_a? GraphicFrame }.transform when :shape return elements.find { |e| !e.shape_properties.preset.nil? }.shape_properties.transform else raise "Dont know this type object - #{object}" end end |