Class: Proselytism::Converters::Base

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/proselytism/converter.rb

Direct Known Subclasses

OpenOffice, PdfImages, PdfToText, PpmToJpeg

Defined Under Namespace

Classes: Error

Instance Method Summary collapse

Instance Method Details

#convert(file_path, options = {}) ⇒ Object

call perform logging duration and potential errors



26
27
28
29
30
31
32
33
34
35
# File 'lib/proselytism/converter.rb', line 26

def convert(file_path, options={})
  log :debug, "#{self.class.name} converted #{file_path} to :#{options[:to]}" do
    begin
      perform(file_path, options)
    rescue Error => e
      log :error, "#{e.class.name} #{e.message}\n#{e.backtrace}\n"
      raise e
    end
  end
end

#destination_file_path(origin, options = {}) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/proselytism/converter.rb', line 17

def destination_file_path(origin, options={})
  if options[:dest]
    options[:dest]
  else
    File.join options[:dir], File.basename(origin).gsub(/\..*$/, options[:folder] ? '' : ".#{options[:to]}")
  end
end

#execute(command) ⇒ Object

execute a command and raise error with the command output if it fails



38
39
40
41
42
43
44
# File 'lib/proselytism/converter.rb', line 38

def execute(command)
  output = `#{command}`
  if $?.exitstatus != 0
    raise self.class::Error, ["#{self.class.name} unable to exec command: #{command}",'--', output,'--'].join("\n")
  end
  $?.exitstatus == 0
end