Sha256: f16697bf3a0802ca7ca45ffac2589c5e6fa028646a8ca36078e18a14c2748014

Contents?: true

Size: 1.24 KB

Versions: 7

Compression:

Stored size: 1.24 KB

Contents

module Hydra::Derivatives::Processors
  class Document < Processor
    include ShellBasedProcessor

    def self.encode(path, options, output_file)
      format = File.extname(output_file).sub('.', '')
      outdir = File.dirname(output_file)
      execute "#{Hydra::Derivatives.libreoffice_path} --invisible --headless --convert-to #{format} --outdir #{outdir} #{path}"
    end

    def encode_file(file_suffix, options = { })
      new_output = ''
      if file_suffix == 'jpg'
        temp_file = File.join(Hydra::Derivatives.temp_file_base, [directives.fetch(:label).to_s, 'pdf'].join('.'))
        new_output = File.join(Hydra::Derivatives.temp_file_base, [File.basename(temp_file).sub(File.extname(temp_file), ''), file_suffix].join('.'))
        self.class.encode(source_path, options, temp_file)
        self.class.encode(temp_file, options, output_file(file_suffix))
        File.unlink(temp_file)
      else
        self.class.encode(source_path, options, output_file(file_suffix))
        new_output = File.join(Hydra::Derivatives.temp_file_base, [directives.fetch(:label).to_s, file_suffix].join('.'))
      end
      out_file = File.open(new_output, "rb")
      output_file_service.call(out_file, directives)
      File.unlink(out_file)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hydra-derivatives-3.1.3 lib/hydra/derivatives/processors/document.rb
hydra-derivatives-3.1.2 lib/hydra/derivatives/processors/document.rb
hydra-derivatives-3.1.1 lib/hydra/derivatives/processors/document.rb
hydra-derivatives-3.1.0 lib/hydra/derivatives/processors/document.rb
hydra-derivatives-3.0.2 lib/hydra/derivatives/processors/document.rb
hydra-derivatives-3.0.1 lib/hydra/derivatives/processors/document.rb
hydra-derivatives-3.0.0 lib/hydra/derivatives/processors/document.rb