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



29
30
31
# File 'lib/rabbit/parser/pdf.rb', line 29

def format_name
  "PDF"
end

.match?(source) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
40
# File 'lib/rabbit/parser/pdf.rb', line 33

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



44
45
46
47
48
49
50
51
52
53
# File 'lib/rabbit/parser/pdf.rb', line 44

def parse
  doc = Poppler::Document.new(:data => @source.read)
  doc.each_with_index do |page, i|
    if i.zero?
      @canvas << PopplerTitleSlide.new(page, doc)
    else
      @canvas << PopplerSlide.new(page)
    end
  end
end