Module: Hydra::Derivatives::Processors::ShellBasedProcessor

Extended by:
ActiveSupport::Concern
Included in:
Document, Jpeg2kImage
Defined in:
lib/hydra/derivatives/processors/shell_based_processor.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

BLOCK_SIZE =
1024

Instance Method Summary collapse

Instance Method Details

#encode_file(file_suffix, options) ⇒ Object


30
31
32
33
34
35
# File 'lib/hydra/derivatives/processors/shell_based_processor.rb', line 30

def encode_file(file_suffix, options)
  temp_file_name = output_file(file_suffix)
  self.class.encode(source_path, options, temp_file_name)
  output_file_service.call(File.open(temp_file_name, 'rb'), directives)
  File.unlink(temp_file_name)
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


26
27
28
# File 'lib/hydra/derivatives/processors/shell_based_processor.rb', line 26

def options_for(_format)
  {}
end

#output_file(file_suffix) ⇒ Object


37
38
39
# File 'lib/hydra/derivatives/processors/shell_based_processor.rb', line 37

def output_file(file_suffix)
  Dir::Tmpname.create(['sufia', ".#{file_suffix}"], Hydra::Derivatives.temp_file_base) {}
end

#processObject

Raises:

  • (ArgumentError)

17
18
19
20
21
22
# File 'lib/hydra/derivatives/processors/shell_based_processor.rb', line 17

def process
  format = directives[:format]
  raise ArgumentError, "You must provide the :format you want to transcode into. You provided #{directives}" unless format
  # TODO: if the source is in the correct format, we could just copy it and skip transcoding.
  encode_file(format, options_for(format))
end