Class: Rabbit::Parser::PDF

Inherits:
Base
  • Object
show all
Includes:
Element
Defined in:
lib/rabbit/parser/pdf.rb

Constant Summary

Constants included from ModuleLoader

ModuleLoader::LOADERS

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize, name

Methods included from ModuleLoader

extend_object, #find_loader, #loaders, #push_loader, #unshift_loader

Constructor Details

This class inherits a constructor from Rabbit::Parser::Base

Class Method Details

.match?(source) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
# File 'lib/rabbit/parser/pdf.rb', line 13

def match?(source)
  extension = source.extension
  if extension.nil?
    source.read.start_with?("%PDF-1.")
  else
    /\Apdf\z/i =~ extension
  end
end

Instance Method Details

#parseObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/rabbit/parser/pdf.rb', line 24

def parse
  doc = Poppler::Document.new(@source.read)

  title_page, *rest = doc.to_a

  @canvas << PopplerTitleSlide.new(title_page, doc)
  rest.each do |page|
    @canvas << PopplerSlide.new(page)
  end
end