Module: Rbpptx

Defined in:
lib/rbpptx.rb,
lib/rbpptx/run.rb,
lib/rbpptx/shape.rb,
lib/rbpptx/slide.rb,
lib/rbpptx/errors.rb,
lib/rbpptx/version.rb,
lib/rbpptx/paragraph.rb,
lib/rbpptx/presentation.rb

Overview

PowerPoint (.pptx) reader/writer for Ruby, modeled after python-pptx.

Rbpptx exposes a single, unified Presentation object that can be loaded from disk, mutated in memory, and written back out:

require "rbpptx"

pres = Rbpptx.open("deck.pptx")
pres.slides.each { |slide| puts slide.shapes.map(&:text).join(" / ") }
pres.close

Block form auto-closes the underlying ZIP:

Rbpptx.open("deck.pptx") do |pres|
  pres.slides.first.shapes.each { |s| puts s.text }
end

Defined Under Namespace

Classes: ClosedPresentationError, Error, Paragraph, Presentation, PresentationFormatError, Run, Shape, Slide, SlideFormatError, SlideNotFoundError, UnsupportedFormatError

Constant Summary collapse

VERSION =

Gem version string, tracked with semantic versioning.

"0.1.0"

Class Method Summary collapse

Class Method Details

.newRbpptx::Presentation

Creates a new empty presentation. Not yet implemented; tracked for future write-from-scratch support.

Returns:

Raises:

  • (NotImplementedError)


56
57
58
# File 'lib/rbpptx.rb', line 56

def new
  raise NotImplementedError, "Rbpptx.new (blank presentation creation) is not implemented yet"
end

.open(path) {|pres| ... } ⇒ Rbpptx::Presentation, Object

Opens an existing .pptx presentation.

When a block is given, the presentation is yielded and automatically closed when the block returns (or raises), mirroring the File.open and Zip::File.open idiom.

Parameters:

  • path (String, #to_path)

    filesystem path to a .pptx file

Yield Parameters:

Returns:

  • (Rbpptx::Presentation, Object)

    the presentation when no block is given, otherwise the block’s return value



41
42
43
44
45
46
47
48
49
50
# File 'lib/rbpptx.rb', line 41

def open(path)
  pres = Presentation.open(path)
  return pres unless block_given?

  begin
    yield pres
  ensure
    pres.close
  end
end