Module: Shared::Dwc::MediaTargetExtensions
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/shared/dwc/media_target_extensions.rb
Overview
A concern on media ‘targets’ (i.e. things that are conveyed or depicted by media) like CollectionObjects and FieldOccurrences.
Constant Summary collapse
- DWC_MEDIA_EXTENSION_MAP =
See rs.gbif.org/extension/ac/audiovisual_2024_11_07.xml and Export::CSV::Dwc::Extension::Media::HEADERS for the original list. The list here is uncommented only for those properties actually mapped by this concern; see concerns on Image, Sound, and Observation for others.
{ coreid: :dwc_media_coreid, # identifier #'dc:type': :dwc_media_dc_type, # TODO: is the prefix the way to do this? #'dcmi:type': :dwc_media_dcmi_type, # 'subtypeLiteral', # 'subtype', # 'title', # 'modified', # TODO: updated_at ?? # 'MetadataDate', # 'metadataLanguageLiteral', # 'metadataLanguage', #providerManagedID: :dwc_media_provider_managed_id, # currently id ?? # #'Rating', # #'commenterLiteral', # #'commenter', # #'comments', # #'reviewerLiteral', # #'reviewer', # #'reviewerComments', # 'available', # 'hasServiceAccessPoint', #'dc:rights': :dwc_media_dc_rights, #'dcterms:rights': :dwc_media_dcterms_rights, #Owner: :dwc_media_owner, # 'UsageTerms', # 'WebStatement', # 'licenseLogoURL', # 'Credit', # 'attributionLogoURL', # 'attributionLinkURL', # #'fundingAttribution', # 'dc:source', # 'dcterms:source', #'dc:creator': :dwc_media_dc_creator, # 'dcterms:creator', # 'providerLiteral', TODO?? # 'provider', TODO?? # 'metadataCreatorLiteral', # 'metadataCreator', # 'metadataProviderLiteral', # 'metadataProvider', description: :dwc_media_description, # currently from depiction/conveyance, but maybe should be image/sound notes?? caption: :dwc_media_caption, # 'language', # 'language', # #'physicalSetting', # 'CVterm', # 'subjectCategoryVocabulary', #tag: :dwc_media_tag, # TODO list tags?? # 'LocationShown', # TODO?? could be AD of depiction/conveyance of image/sound (on otu) # 'WorldRegion', #CountryCode: :dwc_media_country_code, CountryName: :dwc_media_country_name, ProvinceState: :dwc_media_province_state, # 'City', # 'Sublocation', # 'temporal', # 'CreateDate', # 'timeOfDay', #taxonCoverage: :dwc_media_taxon_coverage, scientificName: :dwc_media_scientific_name, # 'identificationQualifier', vernacularName: :dwc_media_vernacular_name, # 'nameAccordingTo', # 'scientificNameID', # 'otherScientificName', identifiedBy: :dwc_media_identified_by, dateIdentified: :dwc_media_date_identified, # 'taxonCount', # #'subjectPart', sex: :dwc_media_sex, lifeStage: :dwc_media_life_stage, # 'subjectOrientation', # 'preparations', # 'LocationCreated', # 'digitizationDate', # #'captureDevice', # #'resourceCreationTechnique', # #'IDofContainingCollection', # 'relatedResourceID', # 'providerID', # 'derivedFrom', associatedSpecimenReference: :dwc_media_associated_specimen_reference, # 'associatedObservationReference', # 'accessURI', #'dc:format': :dwc_media_dc_format, # 'dcterms:format', # 'variantLiteral', # 'variant', # 'variantDescription', # 'furtherInformationURL', #'licensingException', #'serviceExpectation', #'hashFunction', #'hashValue', #PixelXDimension: dwc_pixel_x_dimension, #PixelYDimension: dwc_pixel_y_dimension }.freeze
Instance Method Summary collapse
- #darwin_core_media_extension_rows ⇒ Object
- #dwc_media_associated_specimen_reference(o) ⇒ Object
- #dwc_media_caption(o) ⇒ Object
- #dwc_media_coreid(o) ⇒ Object
-
#dwc_media_country_name(o) ⇒ Object
TODO? country code isn’t cached; we could try to look it up off GAs def dwc_media_country_code(o) end.
- #dwc_media_date_identified(o) ⇒ Object
- #dwc_media_description(o) ⇒ Object
- #dwc_media_identified_by(o) ⇒ Object
- #dwc_media_life_stage(o) ⇒ Object
- #dwc_media_province_state(o) ⇒ Object
- #dwc_media_scientific_name(o) ⇒ Object
- #dwc_media_sex(o) ⇒ Object
- #dwc_media_vernacular_name(o) ⇒ Object
- #extension_map_index(key) ⇒ Object
Instance Method Details
#darwin_core_media_extension_rows ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'app/models/concerns/shared/dwc/media_target_extensions.rb', line 110 def darwin_core_media_extension_rows rv = [] images_array = ( images.map { |i| { image: i, observation: nil }} + observations.map { |o| o.images.map { |i| { image: i, observation: o }} } ).flatten rv += images_array.collect do |i| image_dwc_array = Export::CSV::Dwc::Extension::Media::HEADERS.collect do |h| dwc_reader = DWC_MEDIA_EXTENSION_MAP[h.to_sym] dwc_reader.present? && respond_to?(dwc_reader) ? send(dwc_reader, i[:image]) : nil end image_fields_hash = i[:image].darwin_core_media_extension_image_row # Merge image_fields_hash data into image_dwc_array. image_fields_hash.each { |k, v| image_dwc_array[extension_map_index(k)] = v } if i[:observation] observation_fields_hash = i[:observation].darwin_core_media_extension_image_row observation_fields_hash.each { |k, v| image_dwc_array[extension_map_index(k)] = v } end image_dwc_array end sounds_array = ( sounds.map { |s| { sound: s, observation: nil }} #+ #observations.map { |o| o.sounds.map { |s| { sound: s, observation: o }} } ).flatten rv += sounds_array.collect do |s| sound_dwc_array = Export::CSV::Dwc::Extension::Media::HEADERS.collect do |h| dwc_reader = DWC_MEDIA_EXTENSION_MAP[h.to_sym] dwc_reader.present? && respond_to?(dwc_reader) ? send(dwc_reader, s[:sound]) : nil end sound_fields_hash = s[:sound].darwin_core_media_extension_sound_row # Merge sound_fields_hash data into sound_dwc_array. sound_fields_hash.each { |k, v| sound_dwc_array[extension_map_index(k)] = v } # TODO: bring this back once conveyances are back on Observations. # if s[:observation] # observation_fields_hash = s[:observation].darwin_core_media_extension_sound_row # observation_fields_hash.each { |k, v| sound_dwc_array[extension_map_index(k)] = v } # end sound_dwc_array end rv end |
#dwc_media_associated_specimen_reference(o) ⇒ Object
239 240 241 242 243 |
# File 'app/models/concerns/shared/dwc/media_target_extensions.rb', line 239 def dwc_media_associated_specimen_reference(o) if self.is_a?(CollectionObject) Shared::Api.api_link(self) end end |
#dwc_media_caption(o) ⇒ Object
184 185 186 187 188 189 190 191 192 |
# File 'app/models/concerns/shared/dwc/media_target_extensions.rb', line 184 def dwc_media_caption(o) case o.class.name when 'Image' d = depictions.select { |d| d.image_id == o.id }.first d.caption if d else nil end end |
#dwc_media_coreid(o) ⇒ Object
168 169 170 |
# File 'app/models/concerns/shared/dwc/media_target_extensions.rb', line 168 def dwc_media_coreid(o) dwc_occurrence.id end |
#dwc_media_country_name(o) ⇒ Object
TODO? country code isn’t cached; we could try to look it up off GAs
def dwc_media_country_code(o)
end
198 199 200 |
# File 'app/models/concerns/shared/dwc/media_target_extensions.rb', line 198 def dwc_media_country_name(o) dwc_country end |
#dwc_media_date_identified(o) ⇒ Object
227 228 229 |
# File 'app/models/concerns/shared/dwc/media_target_extensions.rb', line 227 def dwc_media_date_identified(o) dwc_date_identified end |
#dwc_media_description(o) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 |
# File 'app/models/concerns/shared/dwc/media_target_extensions.rb', line 172 def dwc_media_description(o) case o.class.name when 'Image' d = depictions.select { |d| d.image_id == o.id }.first d.figure_label if d when 'Sound' o.name else nil end end |
#dwc_media_identified_by(o) ⇒ Object
223 224 225 |
# File 'app/models/concerns/shared/dwc/media_target_extensions.rb', line 223 def dwc_media_identified_by(o) dwc_identified_by end |
#dwc_media_life_stage(o) ⇒ Object
235 236 237 |
# File 'app/models/concerns/shared/dwc/media_target_extensions.rb', line 235 def dwc_media_life_stage(o) dwc_life_stage end |
#dwc_media_province_state(o) ⇒ Object
202 203 204 |
# File 'app/models/concerns/shared/dwc/media_target_extensions.rb', line 202 def dwc_media_province_state(o) dwc_state_province end |
#dwc_media_scientific_name(o) ⇒ Object
206 207 208 |
# File 'app/models/concerns/shared/dwc/media_target_extensions.rb', line 206 def dwc_media_scientific_name(o) dwc_scientific_name end |
#dwc_media_sex(o) ⇒ Object
231 232 233 |
# File 'app/models/concerns/shared/dwc/media_target_extensions.rb', line 231 def dwc_media_sex(o) dwc_sex end |
#dwc_media_vernacular_name(o) ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'app/models/concerns/shared/dwc/media_target_extensions.rb', line 210 def dwc_media_vernacular_name(o) otu = current_otu return nil if otu.nil? # TODO: include countries? CommonName .joins(:otu) .where(otu: {id: otu.id}) .map(&:name) .join(CollectionObject::DWC_DELIMITER) end |