Module: IiifPrint::Data::FilesetHelper

Included in:
WorkDerivatives
Defined in:
lib/iiif_print/data/fileset_helper.rb

Overview

Mixin module for fileset methods for work, presumes an @work

instance attribute refering to a work object

Instance Method Summary collapse

Instance Method Details

#fileset_idObject



6
7
8
9
10
11
# File 'lib/iiif_print/data/fileset_helper.rb', line 6

def fileset_id
  # if context is itself a string, presume it is a file set id
  return @work if @work.is_a? String
  # if context is not a String, presume a work or fileset context:
  fileset&.id
end

#first_filesetObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/iiif_print/data/fileset_helper.rb', line 13

def first_fileset
  # if context is fileset id (e.g. caller is view partial) string,
  #   get the fileset from that id
  return Hyrax.query_service.find_by(id: @work) if @work.is_a?(String)
  # if "work" context is a FileSet, not actual work, return it
  return @work if @work.is_a?(Hyrax::FileSet) || @work.is_a?(FileSet)
  # in most cases, get from work's members:
  filesets = @work.members.select { |m| m.is_a?(Hyrax::FileSet) || m.is_a?(FileSet) }
  filesets.empty? ? nil : filesets[0]
end