Class: Aoororachain::Loaders::PDFLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/aoororachain/loaders/pdf_loader.rb

Class Method Summary collapse

Class Method Details

.load(file, parser: nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/aoororachain/loaders/pdf_loader.rb', line 8

def self.load(file, parser: nil)
  reader = PDF::Reader.new(file)
  documents = []

   = {source: file, pages: reader.page_count}

  reader.pages.each do |page|
     = .dup
    [:page] = page.number
    text = page.text

    if !parser.nil?
      text,  = parser.parse(text)
      Aoororachain::Util.log_debug("Extracted metadata using parser #{parser.class}", {additional_metadata:})
      .merge!()
    end

    documents << Document.new(text, )
  end

  Aoororachain::Util.log_debug("File loaded", {file:})
  documents
end