class PdfEditor::Shuffle

Attributes

page_order[R]

Page order does not require unique members and is not sorted. This is the base class for other shuffle operations.

resource[R]

Page order does not require unique members and is not sorted. This is the base class for other shuffle operations.

Public Instance Methods

call() click to toggle source
# File lib/pdf_editor/shuffle.rb, line 25
def call
  if resource.nil?
    raise Errors::ResourcesEmptyError, 'Must have a resource to shuffle'
  end
  if page_order.empty?
    raise Errors::PageOrderInvalidError, 'Page order was invalid'
  end
  PdfEditor::Resource.new(
    create_tempfile {run_command}
  )
end
post_init() click to toggle source
# File lib/pdf_editor/shuffle.rb, line 20
def post_init
  @resource   = args[:resource]
  @page_order = args.fetch(:page_order, [])
end

Private Instance Methods

format_command() click to toggle source
# File lib/pdf_editor/shuffle.rb, line 47
def format_command
  page_order.map do |page_num|
    {
      :pdf => resource.path, 
      :start => page_num, 
      :end => page_num
    }
  end
end
run_command() click to toggle source
# File lib/pdf_editor/shuffle.rb, line 39
def run_command
  read_from_io do 
    pdf_runner.cat(format_command)
  end
rescue ::ActivePdftk::CommandError => e 
  raise InvalidInputError, e.message
end