Module: Hydra::Derivatives::ShellBasedProcessor
- Extended by:
- ActiveSupport::Concern
- Included in:
- Document, Jpeg2kImage
- Defined in:
- lib/hydra/derivatives/shell_based_processor.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #encode_file(dest_path, file_suffix, mime_type, options) ⇒ Object
-
#options_for(format) ⇒ Object
override this method in subclass if you want to provide specific options.
- #process ⇒ Object
Instance Method Details
#encode_file(dest_path, file_suffix, mime_type, options) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/hydra/derivatives/shell_based_processor.rb', line 32 def encode_file(dest_path, file_suffix, mime_type, ) out_file = nil output_file = Dir::Tmpname.create(['sufia', ".#{file_suffix}"], Hydra::Derivatives.temp_file_base){} Hydra::Derivatives::TempfileService.create(source_file) do |f| self.class.encode(f.path, , output_file) end out_file = File.open(output_file, "rb") object.add_file(out_file.read, path: dest_path, mime_type: mime_type) File.unlink(output_file) end |
#options_for(format) ⇒ Object
override this method in subclass if you want to provide specific options. returns a hash of options that the specific processors use
28 29 30 |
# File 'lib/hydra/derivatives/shell_based_processor.rb', line 28 def (format) {} end |
#process ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/hydra/derivatives/shell_based_processor.rb', line 16 def process directives.each do |name, args| format = args[:format] raise ArgumentError, "You must provide the :format you want to transcode into. You provided #{args}" unless format # TODO if the source is in the correct format, we could just copy it and skip transcoding. output_file_name = args[:datastream] || output_file_id(name) encode_file(output_file_name, format, new_mime_type(format), (format)) end end |