Class: Hyrax::FileSetTypeService

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

Overview

Note:

this service is for `Hyrax::FileSet` Valkyrie Resources. for ActiveFedora file sets see Hydra::Works::MimeTypes

Resolves file sets to a mime type. Provides a series of utility methods for figuring out what a file set is all about.

Constant Summary collapse

DEFAULT_AUDIO_TYPES =
['audio/mp3', 'audio/mpeg', 'audio/wav',
'audio/x-wave', 'audio/x-wav', 'audio/ogg'].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_set:, characterization_proxy: ::FileSet.characterization_proxy, query_service: Hyrax.custom_queries) ⇒ FileSetTypeService

TODO:

make `file_set_characterization_proxy` (or something better?) application-level configuration.

Returns a new instance of FileSetTypeService.

Parameters:

  • file_set (Hyrax::FileSet)
  • characterization_proxy (Symbol) (defaults to: ::FileSet.characterization_proxy)

    defaults to the setting provided by the application's ActiveFedora `FileSet` class.


26
27
28
29
30
# File 'app/services/hyrax/file_set_type_service.rb', line 26

def initialize(file_set:, characterization_proxy: ::FileSet.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

Instance Attribute Details

#file_setObject (readonly)

Returns the value of attribute file_set


17
18
19
# File 'app/services/hyrax/file_set_type_service.rb', line 17

def file_set
  @file_set
end

Instance Method Details

#audio?Boolean

Returns:

  • (Boolean)

44
45
46
# File 'app/services/hyrax/file_set_type_service.rb', line 44

def audio?
  audio_types.include?(mime_type)
end

#metadataObject


32
33
34
# File 'app/services/hyrax/file_set_type_service.rb', line 32

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

#mime_typeString

Returns:

  • (String)

38
39
40
# File 'app/services/hyrax/file_set_type_service.rb', line 38

def mime_type
  &.mime_type || Hyrax::FileMetadata::GENERIC_MIME_TYPE
end