Module: OoxmlParser::SlideHelper
- Included in:
- Slide
- Defined in:
- lib/ooxml_parser/pptx_parser/presentation/slide/slide_helper.rb
Overview
Methods to help working with slide data
Instance Method Summary collapse
-
#content_distribute(object, slide_size) ⇒ Array<Symbol>
Get content distribution of object.
-
#content_horizontal_align(object, slide_size) ⇒ Symbol
Get horizontal align of object on slide.
-
#content_vertical_align(object, slide_size) ⇒ Symbol
Get vertical align of object on slide.
-
#graphic_frames ⇒ Array<GraphicFrame>
List GraphicFrame elements on slide.
-
#nonempty_elements ⇒ Array
List of not empty element on slide.
-
#transform_of_object(object) ⇒ OOXMLDocumentObject
Get transform property of object, by object type.
Instance Method Details
#content_distribute(object, slide_size) ⇒ Array<Symbol>
Get content distribution of object
62 63 64 65 66 |
# File 'lib/ooxml_parser/pptx_parser/presentation/slide/slide_helper.rb', line 62 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) ⇒ Symbol
Get horizontal align of object on slide
36 37 38 39 40 41 42 43 |
# File 'lib/ooxml_parser/pptx_parser/presentation/slide/slide_helper.rb', line 36 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) ⇒ Symbol
Get vertical align of object on slide
49 50 51 52 53 54 55 56 |
# File 'lib/ooxml_parser/pptx_parser/presentation/slide/slide_helper.rb', line 49 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 ⇒ Array<GraphicFrame>
Returns list GraphicFrame elements on slide.
12 13 14 |
# File 'lib/ooxml_parser/pptx_parser/presentation/slide/slide_helper.rb', line 12 def graphic_frames elements.select { |cur_element| cur_element.is_a?(GraphicFrame) } end |
#nonempty_elements ⇒ Array
Returns list of not empty element on slide.
7 8 9 |
# File 'lib/ooxml_parser/pptx_parser/presentation/slide/slide_helper.rb', line 7 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
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ooxml_parser/pptx_parser/presentation/slide/slide_helper.rb', line 19 def transform_of_object(object) case object when :image elements.find { |e| e.is_a? DocxPicture }.properties.transform when :chart, :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 |