Class: DragonflyPdf::Processors::Rotate

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

Instance Method Summary collapse

Instance Method Details

#call(content, arg) ⇒ Object



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

def call(content, arg)
  rotate_args = case arg
                when String, Symbol
                  fail ArgumentError.new unless arg =~ /north|south|east|west|left|right|down/i
                  "1-end#{arg}"
                when Hash
                  pdf_properties = DragonflyPdf::Analysers::PdfProperties.new.call(content)
                  pdf_properties[:page_numbers].map { |page| [page, arg[page]].compact.join }.join(' ')
  end

  content.shell_update(ext: :pdf) do |old_path, new_path|
    "#{pdftk_command} #{old_path} cat #{rotate_args} output #{new_path}"
  end
end