Class: Hydra::Derivatives::Document
- Includes:
- ShellBasedProcessor
- Defined in:
- lib/hydra/derivatives/document.rb
Instance Attribute Summary
Attributes inherited from Processor
#directives, #object, #source_name
Class Method Summary collapse
Instance Method Summary collapse
- #encode_datastream(dest_dsid, file_suffix, mime_type, options = '') ⇒ Object
- #new_mime_type(format) ⇒ Object
Methods included from ShellBasedProcessor
Methods inherited from Processor
#initialize, #output_datastream, #output_datastream_id, #process, #source_datastream
Constructor Details
This class inherits a constructor from Hydra::Derivatives::Processor
Class Method Details
.encode(path, options, output_file) ⇒ Object
5 6 7 8 9 |
# File 'lib/hydra/derivatives/document.rb', line 5 def self.encode(path, , 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_datastream(dest_dsid, file_suffix, mime_type, options = '') ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/hydra/derivatives/document.rb', line 11 def encode_datastream(dest_dsid, file_suffix, mime_type, = '') output_file = Dir::Tmpname.create(['sufia', ".#{file_suffix}"], Hydra::Derivatives.temp_file_base){} new_output = '' source_datastream.to_tempfile do |f| self.class.encode(f.path, , output_file) new_output = File.join(Hydra::Derivatives.temp_file_base, [File.basename(f.path).sub(File.extname(f.path), ''), file_suffix].join('.')) end out_file = File.open(new_output, "rb") object.add_file_datastream(out_file.read, :dsid=>dest_dsid, :mimeType=>mime_type) File.unlink(out_file) end |
#new_mime_type(format) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/hydra/derivatives/document.rb', line 24 def new_mime_type(format) case format when 'pdf' 'application/pdf' when 'odf' 'application/vnd.oasis.opendocument.text' when 'docx' 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' when 'xslx' 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' when 'pptx' 'application/vnd.openxmlformats-officedocument.presentationml.presentation' else raise "I don't know about the format '#{format}'" end end |