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



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

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



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

def options_for(_format)
  {}
end

#output_file(file_suffix) ⇒ Object



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

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

#processObject

Raises:

  • (ArgumentError)


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

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