Module: OoxmlParser::SlideHelper
- Included in:
- Slide
- Defined in:
- lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide_helper.rb
Overview
Methods to help working with slide data
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
- #nonempty_elements ⇒ Object
-
#transform_of_object(object) ⇒ OOXMLDocumentObject
Get transform property of object, by object type.
Instance Method Details
#content_distribute(object, slide_size) ⇒ Object
46 47 48 49 50 |
# File 'lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide_helper.rb', line 46 def content_distribute(object, ) return %i[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
30 31 32 33 34 35 36 |
# File 'lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide_helper.rb', line 30 def content_horizontal_align(object, ) transform = transform_of_object(object) return :left if transform.offset.x.zero? return :center if OoxmlSize.new((.width.value / 2) - (transform.extents.x.value / 2)) == OoxmlSize.new(transform.offset.x.value) return :right if OoxmlSize.new((.width.value - transform.extents.x.value)) == OoxmlSize.new(transform.offset.x.value) :unknown end |
#content_vertical_align(object, slide_size) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide_helper.rb', line 38 def content_vertical_align(object, ) transform = transform_of_object(object) return :top if transform.offset.y.zero? return :middle if OoxmlSize.new((.height.value / 2) - (transform.extents.y.value / 2)) == OoxmlSize.new(transform.offset.y.value) return :bottom if OoxmlSize.new(.height.value - transform.extents.y.value) == OoxmlSize.new(transform.offset.y.value) :unknown end |
#graphic_frames ⇒ Object
8 9 10 |
# File 'lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide_helper.rb', line 8 def graphic_frames elements.select { |cur_element| cur_element.is_a?(GraphicFrame) } end |
#nonempty_elements ⇒ Object
4 5 6 |
# File 'lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide_helper.rb', line 4 def nonempty_elements elements.reject { |cur_shape| cur_shape.text_body.paragraphs.first.characters.empty? } end |
#transform_of_object(object) ⇒ OOXMLDocumentObject
Get transform property of object, by object type
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide_helper.rb', line 15 def transform_of_object(object) case object when :image elements.find { |e| e.is_a? Picture }.properties.transform when :chart elements.find { |e| e.is_a? GraphicFrame }.transform when :table elements.find { |e| e.is_a? GraphicFrame }.transform when :shape elements.find { |e| !e.shape_properties.preset.nil? }.shape_properties.transform else raise "Dont know this type object - #{object}" end end |