Class: Spotlight::FeaturedImage

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/spotlight/featured_image.rb

Overview

Featured images for browse categories, feature pages, and exhibits

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#upload_idObject

Returns the value of attribute upload_id.



29
30
31
# File 'app/models/spotlight/featured_image.rb', line 29

def upload_id
  @upload_id
end

Instance Method Details

#documentObject



44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/models/spotlight/featured_image.rb', line 44

def document
  return unless document_global_id && source == 'exhibit'

  @document = nil if @document && document_global_id != @document.to_global_id.to_s

  @document ||= GlobalID::Locator.locate document_global_id
rescue Blacklight::Exceptions::RecordNotFound => e
  Rails.logger.info("Exception fetching record by id: #{document_global_id}")
  Rails.logger.info(e)

  nil
end

#file_present?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'app/models/spotlight/featured_image.rb', line 57

def file_present?
  image.file.present?
end

#iiif_tilesourceObject



61
62
63
64
65
66
67
# File 'app/models/spotlight/featured_image.rb', line 61

def iiif_tilesource
  if self[:iiif_tilesource]
    self[:iiif_tilesource]
  elsif file_present?
    Spotlight::Engine.config.iiif_service.info_url(self)
  end
end

#iiif_urlObject



31
32
33
34
35
# File 'app/models/spotlight/featured_image.rb', line 31

def iiif_url
  return if iiif_service_base.blank?

  [iiif_service_base, iiif_region || 'full', image_size.join(','), '0', 'default.jpg'].join('/')
end

#remote_image_url=(url) ⇒ Object

This is used to fetch images given the URL field in the CSV uploads If the image is local, this step will fail, which is okay since the only consumer is CSV uploads and the URL is intended to be remote



40
41
42
# File 'app/models/spotlight/featured_image.rb', line 40

def remote_image_url=(url)
  super url unless url.starts_with? '/'
end

#to_paramObject

Include a hashed updated_at timestamp in the parameter key to bust any browser caching.



71
72
73
# File 'app/models/spotlight/featured_image.rb', line 71

def to_param
  "#{id}-#{Digest::MD5.hexdigest(updated_at.iso8601)}"
end