Module: Shared::Identifiers
- Extended by:
- ActiveSupport::Concern
- Included in:
- AssertedDistribution, BiologicalAssociation, BiologicalAssociationsGraph, BiologicalRelationship, CharacterState, CollectingEvent, CollectionObject, CollectionProfile, CommonName, Container, Descriptor, Document, Extract, FieldOccurrence, GeneAttribute, GeographicArea, Image, Loan, Observation, ObservationMatrix, ObservationMatrixColumnItem, ObservationMatrixRow, ObservationMatrixRowItem, Organization, Otu, Person, Repository, Sequence, SequenceRelationship, Serial, Source, TaxonName, User
- Defined in:
- app/models/concerns/shared/identifiers.rb
Overview
Shared code for objects that have Identifiers.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #dwc_occurrence_id ⇒ Object
- #identified? ⇒ Boolean
- #next_by_identifier ⇒ Object
- #previous_by_identifier ⇒ Object
- #reject_identifiers(attributed) ⇒ Object protected
- #uri ⇒ Object
- #uuid ⇒ Object
Instance Method Details
#dwc_occurrence_id ⇒ Object
111 112 113 |
# File 'app/models/concerns/shared/identifiers.rb', line 111 def dwc_occurrence_id identifiers.where('identifiers.type like ?', 'Identifier::Global::Uuid%').order('identifiers.position ASC').first&.identifier end |
#identified? ⇒ Boolean
115 116 117 118 119 120 121 |
# File 'app/models/concerns/shared/identifiers.rb', line 115 def identified? if respond_to?(:project_id) identifiers.visible(self.project_id).any? else identifiers.any? end end |
#next_by_identifier ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'app/models/concerns/shared/identifiers.rb', line 123 def next_by_identifier # TODO: Memoize i so it can be shared with previous etc. # LIke attr_accessor @navigating_identifier if @navigating_identifier ||= identifiers.where("identifiers.type ILIKE 'Identifier::Local%'").order(:position).first self.class .where(project_id:) .where.not(id:) .with_identifier_type_and_namespace_method(navigating_identifier.type, navigating_identifier.namespace_id, 'ASC') .where('cached_numeric_identifier > ?', navigating_identifier.cached_numeric_identifier) .first else nil end end |
#previous_by_identifier ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'app/models/concerns/shared/identifiers.rb', line 138 def previous_by_identifier if @navigating_identifier ||= identifiers.where("type ILIKE 'Identifier::Local%'").order(:position).first self.class .where(project_id:) .where.not(id:) .with_identifier_type_and_namespace_method(navigating_identifier.type, navigating_identifier.namespace_id, 'DESC') .where('cached_numeric_identifier < ?', navigating_identifier.cached_numeric_identifier) .first else nil end end |
#reject_identifiers(attributed) ⇒ Object (protected)
154 155 156 |
# File 'app/models/concerns/shared/identifiers.rb', line 154 def reject_identifiers(attributed) attributed['identifier'].blank? || attributed['type'].blank? end |
#uri ⇒ Object
103 104 105 |
# File 'app/models/concerns/shared/identifiers.rb', line 103 def uri uris.first&.cached end |
#uuid ⇒ Object
107 108 109 |
# File 'app/models/concerns/shared/identifiers.rb', line 107 def uuid uuids.first&.cached end |