Class: CurationConcerns::ThumbnailPathService

Inherits:
Object
  • Object
show all
Defined in:
app/services/curation_concerns/thumbnail_path_service.rb

Class Method Summary collapse

Class Method Details

.audio_imageObject



32
33
34
# File 'app/services/curation_concerns/thumbnail_path_service.rb', line 32

def audio_image
  ActionController::Base.helpers.image_path 'audio.png'
end

.call(object) ⇒ String

Returns a path to the thumbnail.

Parameters:

  • the (Work, FileSet)

    object to get the thumbnail for

Returns:

  • (String)

    a path to the thumbnail



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/services/curation_concerns/thumbnail_path_service.rb', line 6

def call(object)
  return default_image unless object.thumbnail_id

  thumb = fetch_thumbnail(object)
  return unless thumb
  if thumb.audio?
    audio_image
  elsif thumbnail?(thumb)
    Rails.application.routes.url_helpers.download_path(object.thumbnail_id, file: 'thumbnail')
  else
    default_image
  end
end

.default_imageObject



28
29
30
# File 'app/services/curation_concerns/thumbnail_path_service.rb', line 28

def default_image
  ActionController::Base.helpers.image_path 'default.png'
end

.fetch_thumbnail(object) ⇒ Object



20
21
22
23
24
25
26
# File 'app/services/curation_concerns/thumbnail_path_service.rb', line 20

def fetch_thumbnail(object)
  return object if object.thumbnail_id == object.id
  ::FileSet.load_instance_from_solr(object.thumbnail_id)
rescue ActiveFedora::ObjectNotFoundError
  Rails.logger.error("Couldn't find thumbnail #{object.thumbnail_id} for #{object.id}")
  nil
end

.thumbnail?(thumb) ⇒ Boolean

Returns true if there a file on disk for this object, otherwise false.

Returns:

  • (Boolean)

    true if there a file on disk for this object, otherwise false



37
38
39
# File 'app/services/curation_concerns/thumbnail_path_service.rb', line 37

def thumbnail?(thumb)
  File.exist?(thumbnail_filepath(thumb))
end

.thumbnail_filepath(thumb) ⇒ Object



41
42
43
# File 'app/services/curation_concerns/thumbnail_path_service.rb', line 41

def thumbnail_filepath(thumb)
  CurationConcerns::DerivativePath.derivative_path_for_reference(thumb, 'thumbnail')
end