Module: CollectionObject::DwcExtensions
- Extended by:
- ActiveSupport::Concern
- Includes:
- TaxonworksExtensions, Shared::Dwc::CollectingEventExtensions, Shared::Dwc::MediaTargetExtensions, Shared::Dwc::TaxonDeterminationExtensions, Shared::IsDwcOccurrence
- Included in:
- CollectionObject, BiologicalCollectionObject
- Defined in:
- app/models/collection_object/dwc_extensions.rb
Defined Under Namespace
Modules: TaxonworksExtensions
Constant Summary
Constants included from Shared::IsDwcOccurrence
Shared::IsDwcOccurrence::DWC_DELIMITER, Shared::IsDwcOccurrence::VIEW_EXCLUSIONS
Instance Method Summary collapse
- #dwc_associated_media ⇒ Object
- #dwc_associated_taxa ⇒ Object
- #dwc_caste ⇒ Object
- #dwc_catalog_number ⇒ Object
-
#dwc_collection_code ⇒ Object
TODO: optimize by finding all relevant identifiers in one query, then looping through them.
- #dwc_event_time ⇒ Object
- #dwc_higher_classification ⇒ Object
-
#dwc_individual_count ⇒ Object
TODO: handle ranged lots.
-
#dwc_institution_code ⇒ Object
we assert custody, NOT ownership.
-
#dwc_institution_id ⇒ Object
we assert custody, NOT ownership.
-
#dwc_internal_attribute_for(target = :collection_object, dwc_term_name) ⇒ Object
TODO: duplicated in CE extension.
-
#dwc_life_stage ⇒ Object
TODO: consider CVT attributes with Predicates linked to URIs.
- #dwc_occurrence_remarks ⇒ Object
- #dwc_occurrence_status ⇒ Object
- #dwc_other_catalog_numbers ⇒ Object
- #dwc_preparations ⇒ Object
- #dwc_record_number ⇒ Object
-
#dwc_sex ⇒ Object
TODO: consider CVT attributes with Predicates linked to URIs.
-
#dwc_type_status ⇒ Object
holotype of Ctenomys sociabilis.
-
#dwc_verbatim_label ⇒ Object
use buffered if any if not check CE verbatim_label.
- #is_fossil? ⇒ Boolean
Methods included from Shared::IsDwcOccurrence
#dwc_occurrence_attribute_values, #dwc_occurrence_attributes, #dwc_occurrence_id, #get_dwc_occurrence, #set_dwc_occurrence
Instance Method Details
#dwc_associated_media ⇒ Object
147 148 149 |
# File 'app/models/collection_object/dwc_extensions.rb', line 147 def dwc_associated_media images.collect{|i| Shared::Api.api_link(i, i.image_file_fingerprint) }.join(CollectionObject::DWC_DELIMITER).presence end |
#dwc_associated_taxa ⇒ Object
152 153 154 |
# File 'app/models/collection_object/dwc_extensions.rb', line 152 def dwc_associated_taxa dwc_internal_attribute_for(:collection_object, :associatedTaxa) end |
#dwc_caste ⇒ Object
232 233 234 235 |
# File 'app/models/collection_object/dwc_extensions.rb', line 232 def dwc_caste biocuration_classes.tagged_with_uri(::DWC_ATTRIBUTE_URIS[:caste]) .pluck(:name)&.join(', ').presence # TODO: Use delimeter! end |
#dwc_catalog_number ⇒ Object
166 167 168 |
# File 'app/models/collection_object/dwc_extensions.rb', line 166 def dwc_catalog_number catalog_number_cached # via delegation end |
#dwc_collection_code ⇒ Object
TODO: optimize by finding all relevant identifiers in one query, then looping through them
158 159 160 |
# File 'app/models/collection_object/dwc_extensions.rb', line 158 def dwc_collection_code catalog_number_namespace&.verbatim_short_name || catalog_number_namespace&.short_name end |
#dwc_event_time ⇒ Object
274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'app/models/collection_object/dwc_extensions.rb', line 274 def dwc_event_time return unless collecting_event %w{start_time end_time} .map { |t| %w{hour minute second} .map { |p| collecting_event["#{t}_#{p}"] } .map { |p| '%02d' % p if p } # At least two digits } .map { |t| t.compact.join(':') } .reject(&:blank?) .join('/').presence end |
#dwc_higher_classification ⇒ Object
248 249 250 251 252 253 254 |
# File 'app/models/collection_object/dwc_extensions.rb', line 248 def dwc_higher_classification v = taxonomy.values.collect{|a| a.kind_of?(Array) ? a.second : a} v.shift v.pop v.compact v.join(CollectionObject::DWC_DELIMITER).presence end |
#dwc_individual_count ⇒ Object
TODO: handle ranged lots
270 271 272 |
# File 'app/models/collection_object/dwc_extensions.rb', line 270 def dwc_individual_count total end |
#dwc_institution_code ⇒ Object
we assert custody, NOT ownership
259 260 261 |
# File 'app/models/collection_object/dwc_extensions.rb', line 259 def dwc_institution_code repository_acronym end |
#dwc_institution_id ⇒ Object
we assert custody, NOT ownership
264 265 266 267 |
# File 'app/models/collection_object/dwc_extensions.rb', line 264 def dwc_institution_id # TODO: identifiers on Repositories repository_url || repository_institutional_LSID end |
#dwc_internal_attribute_for(target = :collection_object, dwc_term_name) ⇒ Object
TODO: duplicated in CE extension
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'app/models/collection_object/dwc_extensions.rb', line 177 def dwc_internal_attribute_for(target = :collection_object, dwc_term_name) return nil if dwc_term_name.nil? case target when :collecting_event return nil unless collecting_event collecting_event.internal_attributes.includes(:predicate) .where( controlled_vocabulary_terms: {uri: ::DWC_ATTRIBUTE_URIS[dwc_term_name.to_sym] }) .pluck(:value)&.join(', ').presence when :collection_object internal_attributes.includes(:predicate) .where( controlled_vocabulary_terms: {uri: ::DWC_ATTRIBUTE_URIS[dwc_term_name.to_sym] }) .pluck(:value)&.join(', ').presence else nil end end |
#dwc_life_stage ⇒ Object
TODO: consider CVT attributes with Predicates linked to URIs
221 222 223 224 |
# File 'app/models/collection_object/dwc_extensions.rb', line 221 def dwc_life_stage biocuration_classes.tagged_with_uri(::DWC_ATTRIBUTE_URIS[:lifeStage]) .pluck(:name)&.join(', ').presence # `.presence` is a Rails extension end |
#dwc_occurrence_remarks ⇒ Object
142 143 144 |
# File 'app/models/collection_object/dwc_extensions.rb', line 142 def dwc_occurrence_remarks notes.collect{|n| n.text}&.join(CollectionObject::DWC_DELIMITER).presence end |
#dwc_occurrence_status ⇒ Object
137 138 139 |
# File 'app/models/collection_object/dwc_extensions.rb', line 137 def dwc_occurrence_status 'present' end |
#dwc_other_catalog_numbers ⇒ Object
170 171 172 173 |
# File 'app/models/collection_object/dwc_extensions.rb', line 170 def dwc_other_catalog_numbers i = identifiers.where.not('type ilike ?', 'Identifier::Global::Uuid%').where.not(cached: catalog_number_cached).order(:position).to_a i.map(&:cached).join(CollectionObject::DWC_DELIMITER).presence end |
#dwc_preparations ⇒ Object
287 288 289 |
# File 'app/models/collection_object/dwc_extensions.rb', line 287 def dwc_preparations preparation_type_name end |
#dwc_record_number ⇒ Object
162 163 164 |
# File 'app/models/collection_object/dwc_extensions.rb', line 162 def dwc_record_number record_number_cached # via delegation end |
#dwc_sex ⇒ Object
TODO: consider CVT attributes with Predicates linked to URIs
227 228 229 230 |
# File 'app/models/collection_object/dwc_extensions.rb', line 227 def dwc_sex biocuration_classes.tagged_with_uri(::DWC_ATTRIBUTE_URIS[:sex]) .pluck(:name)&.join(', ').presence # TODO: Use delimeter! end |
#dwc_type_status ⇒ Object
holotype of Ctenomys sociabilis. Pearson O. P., and M. I. Christie. 1985. Historia Natural, 5(37):388, holotype of Pinus abies | holotype of Picea abies
242 243 244 245 246 |
# File 'app/models/collection_object/dwc_extensions.rb', line 242 def dwc_type_status type_materials.all.collect{|t| ApplicationController.helpers.label_for_type_material(t) }.join(CollectionObject::DWC_DELIMITER).presence end |
#dwc_verbatim_label ⇒ Object
use buffered if any if not check CE verbatim_label
131 132 133 134 135 |
# File 'app/models/collection_object/dwc_extensions.rb', line 131 def dwc_verbatim_label b = [buffered_collecting_event, buffered_determinations, buffered_other_labels].compact return b.join("\n\n") if b.present? collecting_event&.verbatim_label.presence end |
#is_fossil? ⇒ Boolean
237 238 239 |
# File 'app/models/collection_object/dwc_extensions.rb', line 237 def is_fossil? biocuration_classes.where(uri: DWC_FOSSIL_URI).any? end |