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

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

.format_nameObject



13
14
15
# File 'lib/rabbit/parser/pdf.rb', line 13

def format_name
  "PDF"
end

.match?(source) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
# File 'lib/rabbit/parser/pdf.rb', line 17

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



28
29
30
31
32
33
34
35
36
37
# File 'lib/rabbit/parser/pdf.rb', line 28

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