Sha256: 7fbc9b15a310c325cf9653aedd9000b33cdc7233ff41034a5bbe7f0971711c7f

Contents?: true

Size: 1.53 KB

Versions: 20

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

module Hyrax
  ##
  # Resolves file sets to a mime type. Provides a series of utility methods for
  # figuring out what a file set is all about.
  #
  # @note this service is for `Hyrax::FileSet` Valkyrie Resources. for
  #   ActiveFedora file sets see Hydra::Works::MimeTypes
  class FileSetTypeService
    DEFAULT_AUDIO_TYPES = ['audio/mp3', 'audio/mpeg', 'audio/wav',
                           'audio/x-wave', 'audio/x-wav', 'audio/ogg'].freeze

    ##
    # @!attribute [r] file_set
    #   @return [Hyrax::FileSet]
    attr_reader :file_set

    ##
    # @param [Hyrax::FileSet] file_set
    # @param [Symbol] characterization_proxy defaults to the setting provided by
    #   the application's ActiveFedora `FileSet` class.
    def initialize(file_set:, characterization_proxy: Hyrax.config.characterization_proxy, query_service: Hyrax.custom_queries)
      @file_set = file_set
      @proxy_use = Hyrax::FileMetadata::Use.uri_for(use: characterization_proxy)
      @queries = query_service
    end

    def metadata
      @metadata ||= @queries.find_many_file_metadata_by_use(resource: file_set, use: @proxy_use).first
    end

    ##
    # @return [String]
    def mime_type
      metadata&.mime_type || Hyrax::FileMetadata::GENERIC_MIME_TYPE
    end

    ##
    # @return [Boolean]
    def audio?
      audio_types.include?(mime_type)
    end

    private

    def audio_types
      return ::FileSet.audio_mime_types if defined?(::FileSet) && ::FileSet.respond_to?(:audio_mime_types)
      DEFAULT_AUDIO_TYPES
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
hyrax-5.1.0.pre.beta1 app/services/hyrax/file_set_type_service.rb
hyrax-5.0.4 app/services/hyrax/file_set_type_service.rb
hyrax-5.0.3 app/services/hyrax/file_set_type_service.rb
hyrax-5.0.2 app/services/hyrax/file_set_type_service.rb
hyrax-5.0.1 app/services/hyrax/file_set_type_service.rb
hyrax-5.0.0 app/services/hyrax/file_set_type_service.rb
hyrax-5.0.0.rc3 app/services/hyrax/file_set_type_service.rb
hyrax-5.0.0.rc2 app/services/hyrax/file_set_type_service.rb
hyrax-5.0.0.rc1 app/services/hyrax/file_set_type_service.rb
hyrax-3.6.0 app/services/hyrax/file_set_type_service.rb
hyrax-4.0.0 app/services/hyrax/file_set_type_service.rb
hyrax-4.0.0.rc3 app/services/hyrax/file_set_type_service.rb
hyrax-4.0.0.rc2 app/services/hyrax/file_set_type_service.rb
hyrax-4.0.0.rc1 app/services/hyrax/file_set_type_service.rb
hyrax-3.5.0 app/services/hyrax/file_set_type_service.rb
hyrax-4.0.0.beta2 app/services/hyrax/file_set_type_service.rb
hyrax-3.4.2 app/services/hyrax/file_set_type_service.rb
hyrax-4.0.0.beta1 app/services/hyrax/file_set_type_service.rb
hyrax-3.4.1 app/services/hyrax/file_set_type_service.rb
hyrax-3.4.0 app/services/hyrax/file_set_type_service.rb