Class: Rbpptx::Slide

Inherits:
Object
  • Object
show all
Defined in:
lib/rbpptx/slide.rb

Overview

A single slide loaded from a presentation’s ZIP container.

Parsing of the slide’s XML payload is deferred until #shapes is first called and then cached, so simply enumerating slides via Presentation#slides does not pay the per-slide parse cost.

Constant Summary collapse

P_NS =
"http://schemas.openxmlformats.org/presentationml/2006/main".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(zip:, part_name:) ⇒ Slide

Returns a new instance of Slide.

Parameters:

  • zip (Zip::File)

    the open package

  • part_name (String)

    absolute part name (no leading slash)



16
17
18
19
20
# File 'lib/rbpptx/slide.rb', line 16

def initialize(zip:, part_name:)
  @zip = zip
  @part_name = part_name
  @dirty = false
end

Instance Attribute Details

#part_nameString (readonly)

Returns the part name of the slide inside the package, e.g. “ppt/slides/slide1.xml”.

Returns:

  • (String)

    the part name of the slide inside the package, e.g. “ppt/slides/slide1.xml”



12
13
14
# File 'lib/rbpptx/slide.rb', line 12

def part_name
  @part_name
end

Instance Method Details

#clear_dirty!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



54
55
56
# File 'lib/rbpptx/slide.rb', line 54

def clear_dirty!
  @dirty = false
end

#dirty?Boolean

Returns whether any shape on this slide has been mutated since load.

Returns:

  • (Boolean)

    whether any shape on this slide has been mutated since load



35
36
37
# File 'lib/rbpptx/slide.rb', line 35

def dirty?
  @dirty
end

#mark_dirty!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Marks the slide as dirty. Called by Rbpptx::Shape setters; not part of the public API.



43
44
45
# File 'lib/rbpptx/slide.rb', line 43

def mark_dirty!
  @dirty = true
end

#nameString

Returns the slide’s basename without extension, e.g. “slide1”.

Returns:

  • (String)

    the slide’s basename without extension, e.g. “slide1”



23
24
25
# File 'lib/rbpptx/slide.rb', line 23

def name
  File.basename(@part_name, ".xml")
end

#shapesArray<Shape>

Returns <p:sp> children of the slide’s shape tree, in document order.

Returns:

  • (Array<Shape>)

    <p:sp> children of the slide’s shape tree, in document order



29
30
31
# File 'lib/rbpptx/slide.rb', line 29

def shapes
  @shapes ||= build_shapes
end

#to_xmlString

Returns the slide’s XML, reflecting any in-memory mutations. The XML declaration is preserved.

Returns:

  • (String)

    the slide’s XML, reflecting any in-memory mutations. The XML declaration is preserved.



49
50
51
# File 'lib/rbpptx/slide.rb', line 49

def to_xml
  doc.to_xml
end