Class: Hydra::Derivatives::Processors::Document

Inherits:
Processor
  • Object
show all
Includes:
ShellBasedProcessor
Defined in:
lib/hydra/derivatives/processors/document.rb

Constant Summary

Constants included from ShellBasedProcessor

ShellBasedProcessor::BLOCK_SIZE

Instance Attribute Summary

Attributes inherited from Processor

#directives, #output_file_service, #source_path

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ShellBasedProcessor

#options_for, #output_file, #process

Methods inherited from Processor

#initialize, #output_file, #output_file_id, #output_filename_for, #process

Constructor Details

This class inherits a constructor from Hydra::Derivatives::Processors::Processor

Class Method Details

.encode(path, options, output_file) ⇒ Object



5
6
7
8
9
# File 'lib/hydra/derivatives/processors/document.rb', line 5

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

Instance Method Details

#encode_file(file_suffix, options = { }) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/hydra/derivatives/processors/document.rb', line 11

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