class BPL::Derivatives::Processors::Document
Public Class Methods
encode(path, format, outdir)
click to toggle source
# File lib/bpl/derivatives/processors/document.rb, line 5 def self.encode(path, format, outdir) execute "#{BPL::Derivatives.config.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/bpl/derivatives/processors/document.rb, line 12 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/bpl/derivatives/processors/document.rb, line 40 def convert_to(format) self.class.encode(source_path, format, BPL::Derivatives.config.temp_file_base) File.join(BPL::Derivatives.config.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/bpl/derivatives/processors/document.rb, line 22 def convert_to_format if directives.fetch(:format) == "jpg" object.source_path = converted_file BPL::Derivatives::Processors::Image.new(object, directives).process else finalize_derivative_output(File.read(converted_file)) end end
converted_file()
click to toggle source
# File lib/bpl/derivatives/processors/document.rb, line 32 def converted_file @converted_file ||= if directives.fetch(:format) == "jpg" convert_to("pdf") else convert_to(directives.fetch(:format)) end end