Class: ActiveBlob::Blob::PDF

Inherits:
ActiveBlob::Blob show all
Defined in:
app/models/activeblob/blob/pdf.rb

Instance Attribute Summary

Attributes inherited from ActiveBlob::Blob

#data

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ActiveBlob::Blob

#extension, #file, #file=, new, #open, #url, #url=

Methods included from ActiveBlob::BlobHelpers

#file_content_type, #file_sha1, filename_from_file

Class Method Details

.process(record, path) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'app/models/activeblob/blob/pdf.rb', line 21

def self.process(record, path)
  require 'pdf-reader' unless defined?(PDF::Reader)

  record. = {
    'pages' => PDF::Reader.new(path).pages.map { |page|
      { 'width' => page.width, 'height' => page.height }
    }
  }
end

Instance Method Details

#aspect_ratioObject



9
10
11
12
13
14
15
16
17
18
19
# File 'app/models/activeblob/blob/pdf.rb', line 9

def aspect_ratio
  first_page = ['pages']&.first
  return nil unless first_page

  width = first_page['width'].to_f
  height = first_page['height'].to_f

  return nil if height.zero?

  width / height
end

#page_countObject



5
6
7
# File 'app/models/activeblob/blob/pdf.rb', line 5

def page_count
  ['pages']&.size || 0
end