Class: Hyrax::FileSetDerivativesService

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/file_set_derivatives_service.rb

Overview

Responsible for creating and cleaning up the derivatives of a file_set

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_set) ⇒ FileSetDerivativesService

Returns a new instance of FileSetDerivativesService.

Parameters:

  • file_set (Hyrax::FileSet)

    At least for this class, it must have #uri and #mime_type


8
9
10
# File 'app/services/hyrax/file_set_derivatives_service.rb', line 8

def initialize(file_set)
  @file_set = file_set
end

Instance Attribute Details

#file_setObject (readonly)

Returns the value of attribute file_set


4
5
6
# File 'app/services/hyrax/file_set_derivatives_service.rb', line 4

def file_set
  @file_set
end

Instance Method Details

#cleanup_derivativesObject


12
13
14
15
16
# File 'app/services/hyrax/file_set_derivatives_service.rb', line 12

def cleanup_derivatives
  derivative_path_factory.derivatives_for_reference(file_set).each do |path|
    FileUtils.rm_f(path)
  end
end

#create_derivatives(filename) ⇒ Object


22
23
24
25
26
27
28
29
30
# File 'app/services/hyrax/file_set_derivatives_service.rb', line 22

def create_derivatives(filename)
  case mime_type
  when *file_set.class.pdf_mime_types             then create_pdf_derivatives(filename)
  when *file_set.class.office_document_mime_types then create_office_document_derivatives(filename)
  when *file_set.class.audio_mime_types           then create_audio_derivatives(filename)
  when *file_set.class.video_mime_types           then create_video_derivatives(filename)
  when *file_set.class.image_mime_types           then create_image_derivatives(filename)
  end
end

#derivative_url(destination_name) ⇒ Object

The destination_name parameter has to match up with the file parameter passed to the DownloadsController


34
35
36
37
# File 'app/services/hyrax/file_set_derivatives_service.rb', line 34

def derivative_url(destination_name)
  path = derivative_path_factory.derivative_path_for_reference(file_set, destination_name)
  URI("file://#{path}").to_s
end

#valid?Boolean

Returns:

  • (Boolean)

18
19
20
# File 'app/services/hyrax/file_set_derivatives_service.rb', line 18

def valid?
  supported_mime_types.include?(mime_type)
end