Module: Shared::Dwc::MediaExtensions

Extended by:
ActiveSupport::Concern
Included in:
Image::DwcMediaExtensions, Sound::DwcMediaExtensions
Defined in:
app/models/concerns/shared/dwc/media_extensions.rb

Overview

A concern on media items like images and sounds.

Constant Summary collapse

DWC_MEDIA_SHARED_EXTENSION_MAP =

Shared implementation amongst all media sources.

{
  identifier: :dwc_media_identifier,
  providerManagedID: :dwc_media_provider_managed_id, # TODO currently .id ??
  'dc:rights': :dwc_media_dc_rights,
  'dcterms:rights': :dwc_media_dcterms_rights,
  Owner: :dwc_media_owner,
  'dc:creator': :dwc_media_dc_creator,
}.freeze

Instance Method Summary collapse

Instance Method Details

#dwc_media_dc_creatorObject



48
49
50
51
52
53
54
55
# File 'app/models/concerns/shared/dwc/media_extensions.rb', line 48

def dwc_media_dc_creator
  self.class
    .joins(attribution: {roles: :person})
    .where(roles: {type: 'AttributionCreator'})
    .where(id: id)
    .select('people.cached')
    .map { |c| c.cached }.join(CollectionObject::DWC_DELIMITER)
end

#dwc_media_dc_rightsObject



25
26
27
# File 'app/models/concerns/shared/dwc/media_extensions.rb', line 25

def dwc_media_dc_rights
  dwc_media_dcterms_rights
end

#dwc_media_dcterms_rightsObject



29
30
31
32
33
34
35
36
37
# File 'app/models/concerns/shared/dwc/media_extensions.rb', line 29

def dwc_media_dcterms_rights
  CREATIVE_COMMONS_LICENSES[
    self.class
      .joins(:attribution)
      .where(id: id)
      .select('attributions.license')
      .first&.license
  ]&.[](:link)
end

#dwc_media_identifierObject



15
16
17
18
19
# File 'app/models/concerns/shared/dwc/media_extensions.rb', line 15

def dwc_media_identifier
  # Images and sounds are unlikely to have a uuid or uri, so namespace with
  # class name (this field is suposed to be unique).
  "#{self.class.name.downcase}:#{uuid || uri || id}"
end

#dwc_media_ownerObject



39
40
41
42
43
44
45
46
# File 'app/models/concerns/shared/dwc/media_extensions.rb', line 39

def dwc_media_owner
  self.class
    .joins(attribution: {roles: :person})
    .where(roles: {type: 'AttributionOwner'})
    .where(id: id)
    .select('people.cached')
    .map { |o| o.cached }.join(CollectionObject::DWC_DELIMITER)
end

#dwc_media_provider_managed_idObject



21
22
23
# File 'app/models/concerns/shared/dwc/media_extensions.rb', line 21

def dwc_media_provider_managed_id
  id
end