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

Instance Method Details

#content_distribute(object, slide_size) ⇒ Array<Symbol>

Get content distribution of object

Parameters:

  • object (Symbol)

    object to get

  • slide_size (SlideSize)

    size of slide

Returns:

  • (Array<Symbol>)

    type of align



62
63
64
65
66
# File 'lib/ooxml_parser/pptx_parser/presentation/slide/slide_helper.rb', line 62

def content_distribute(object, slide_size)
  return %i[horizontally vertically] if content_horizontal_align(object, slide_size) == :center && content_vertical_align(object, slide_size) == :middle
  return [:horizontally] if content_horizontal_align(object, slide_size) == :center
  return [:vertically] if content_vertical_align(object, slide_size) == :middle
end

#content_horizontal_align(object, slide_size) ⇒ Symbol

Get horizontal align of object on slide

Parameters:

  • object (Symbol)

    object to get

  • slide_size (SlideSize)

    size of slide

Returns:

  • (Symbol)

    type of align



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, slide_size)
  transform = transform_of_object(object)
  return :left if transform.offset.x.zero?
  return :center if OoxmlSize.new((slide_size.width.value / 2) - (transform.extents.x.value / 2)) == OoxmlSize.new(transform.offset.x.value)
  return :right if OoxmlSize.new((slide_size.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

Parameters:

  • object (Symbol)

    object to get

  • slide_size (SlideSize)

    size of slide

Returns:

  • (Symbol)

    type of align



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, slide_size)
  transform = transform_of_object(object)
  return :top if transform.offset.y.zero?
  return :middle if OoxmlSize.new((slide_size.height.value / 2) - (transform.extents.y.value / 2)) == OoxmlSize.new(transform.offset.y.value)
  return :bottom if OoxmlSize.new(slide_size.height.value - transform.extents.y.value) == OoxmlSize.new(transform.offset.y.value)

  :unknown
end

#graphic_framesArray<GraphicFrame>

Returns list GraphicFrame elements on slide.

Returns:

  • (Array<GraphicFrame>)

    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_elementsArray

Returns list of not empty element on slide.

Returns:

  • (Array)

    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

Parameters:

  • object (Symbol)

    type of object: :image, :chart, :table, :shape

Returns:



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