class Hydra::Derivatives::Processors::Document

Public Class Methods

encode(path, format, outdir) click to toggle source
# File lib/hydra/derivatives/processors/document.rb, line 8
def self.encode(path, format, outdir)
  execute "#{Hydra::Derivatives.libreoffice_path} --invisible --headless --convert-to #{format} --outdir #{outdir} #{Shellwords.escape(path)}"
end

Public Instance Methods

encode_file(_file_suffix, _options = {}) click to toggle source

Converts the document to the format specified in the directives hash. TODO: file_suffix and options are passed from ShellBasedProcessor.process but are not needed.

A refactor could simplify this.
# File lib/hydra/derivatives/processors/document.rb, line 15
def encode_file(_file_suffix, _options = {})
  convert_to_format
ensure
  FileUtils.rm_f(converted_file)
end

Private Instance Methods

convert_to(format) click to toggle source
# File lib/hydra/derivatives/processors/document.rb, line 41
def convert_to(format)
  self.class.encode(source_path, format, Hydra::Derivatives.temp_file_base)
  File.join(Hydra::Derivatives.temp_file_base, [File.basename(source_path, ".*"), format].join('.'))
end
convert_to_format() click to toggle source

For jpeg files, a pdf is created from the original source and then passed to the Image processor class so we can get a better conversion with resizing options. Otherwise, the ::encode method is used.

# File lib/hydra/derivatives/processors/document.rb, line 25
def convert_to_format
  if directives.fetch(:format) == "jpg"
    Hydra::Derivatives::Processors::Image.new(converted_file, directives).process
  else
    output_file_service.call(File.open(converted_file, 'rb'), directives)
  end
end
converted_file() click to toggle source
# File lib/hydra/derivatives/processors/document.rb, line 33
def converted_file
  @converted_file ||= if directives.fetch(:format) == "jpg"
                        convert_to("pdf")
                      else
                        convert_to(directives.fetch(:format))
                      end
end