Class: PdfCover::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/pdf_cover/converter.rb

Defined Under Namespace

Classes: CommandFailedError, CommandNotFoundError, InvalidOption

Constant Summary collapse

DEFAULT_FORMAT =

NOTE: Update the generate_jpegs.sh script when changing these values

"jpeg".freeze
DEFAULT_QUALITY =
85
DEFAULT_RESOLUTION =
300
DEFAULT_ANTIALIASING =
4
COMMAND_EXECUTION_SUCCESS_CODE =
0
COMMAND_NOT_FOUND_CODE =
127

Instance Method Summary collapse

Constructor Details

#initialize(file, options = {}) ⇒ Converter

Returns a new instance of Converter.



32
33
34
35
# File 'lib/pdf_cover/converter.rb', line 32

def initialize(file, options = {})
  @file = file
  extract_options(options)
end

Instance Method Details

#converted_fileObject



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/pdf_cover/converter.rb', line 39

def converted_file
  parameters = build_parameters(file_path, device)
  stdout_str, stderr_str, status = execute_command("gs #{parameters}")

  case status
    when COMMAND_EXECUTION_SUCCESS_CODE then destination_file
    when COMMAND_NOT_FOUND_CODE then fail CommandNotFoundError
    else fail CommandFailedError.new(stdout_str, stderr_str)
  end
rescue => e
  destination_file.close
  raise e
end