Class: DragonflyPdf::Processors::PageThumb

Inherits:
Object
  • Object
show all
Defined in:
lib/dragonfly_pdf/processors/page_thumb.rb

Instance Method Summary collapse

Instance Method Details

#call(content, page, geometry = nil, options = {}) ⇒ Object

Raises:



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/dragonfly_pdf/processors/page_thumb.rb', line 4

def call(content, page, geometry = nil, options = {})
  raise UnsupportedFormat unless content.ext
  raise UnsupportedFormat unless SUPPORTED_FORMATS.include?(content.ext.downcase)

  options = DragonflyPdf.stringify_keys(options)
  format = options.delete('format') { 'jpg' }.to_s

  convert(content, page, geometry, format)

  unless %w[pdf png svg].include?(format)
    thumb(content, geometry, format, options)
  end

  content.meta['format'] = format
  content.ext = format
  content.meta['mime_type'] = nil # don't need it as we have ext now
end

#update_url(attrs, _page, _geometry = nil, options = {}) ⇒ Object



22
23
24
25
# File 'lib/dragonfly_pdf/processors/page_thumb.rb', line 22

def update_url(attrs, _page, _geometry = nil, options = {})
  options = options.each_with_object({}) { |(k, v), memo| memo[k.to_s] = v } # stringify keys
  attrs.ext = options.fetch('format', 'jpg').to_s
end