Module: Shared::Citations
- Extended by:
- ActiveSupport::Concern
- Included in:
- AnatomicalPart, AssertedDistribution, BiologicalAssociation, BiologicalAssociationsGraph, BiologicalRelationship, CharacterState, CollectingEvent, CollectionObject, CommonName, Confidence, Content, Conveyance, DataAttribute, Descriptor, Extract, FieldOccurrence, Gazetteer, Georeference, Image, Lead, Observation, ObservationMatrix, ObservationMatrixRowItem, Otu, OtuRelationship, Protocol, Sound, TaxonDetermination, TaxonName, TaxonNameClassification, TaxonNameRelationship, TypeMaterial
- Defined in:
- app/models/concerns/shared/citations.rb
Overview
Shared code for Citations.
The default behaviour with order by youngest source and oldest source is to place records with NIL last in the list. When multiple citations exist the earliest or latest is used in the sort order.
Instance Method Summary collapse
- #cited? ⇒ Boolean
- #mark_citations_for_destruction ⇒ Object
-
#nomenclature_date ⇒ Date?
(also: #source_nomenclature_date)
!! Over-riden in various places, but it shouldn't be See Source::Bibtex for context as to how this is built.
- #origin_citation_source_id ⇒ Object
- #reject_citations(attributed) ⇒ Object protected
-
#requires_citation? ⇒ Boolean
If at least one citation is required override this with true in including class.
- #sources_by_topic_id(topic_id) ⇒ Object
Instance Method Details
#cited? ⇒ Boolean
119 120 121 |
# File 'app/models/concerns/shared/citations.rb', line 119 def cited? self.citations.any? end |
#mark_citations_for_destruction ⇒ Object
123 124 125 |
# File 'app/models/concerns/shared/citations.rb', line 123 def mark_citations_for_destruction citations.map(&:mark_for_destruction) end |
#nomenclature_date ⇒ Date? Also known as: source_nomenclature_date
!! Over-riden in various places, but it shouldn't be See Source::Bibtex for context as to how this is built.
94 95 96 97 98 99 |
# File 'app/models/concerns/shared/citations.rb', line 94 def nomenclature_date self.class.joins(citations: [:source]) .where(citations: {citation_object: self, is_original: true}) .select('sources.cached_nomenclature_date') .first&.cached_nomenclature_date end |
#origin_citation_source_id ⇒ Object
103 104 105 106 107 |
# File 'app/models/concerns/shared/citations.rb', line 103 def origin_citation_source_id if origin_citation && origin_citation.source_id.blank? errors.add(:base, 'the origin citation must have a source') end end |
#reject_citations(attributed) ⇒ Object (protected)
129 130 131 132 133 134 135 |
# File 'app/models/concerns/shared/citations.rb', line 129 def reject_citations(attributed) if (attributed['source_id'].blank? && attributed['source'].blank?) return true if new_record? return true if attributed['pages'].blank? end false end |
#requires_citation? ⇒ Boolean
Returns if at least one citation is required override this with true in including class.
115 116 117 |
# File 'app/models/concerns/shared/citations.rb', line 115 def requires_citation? false end |
#sources_by_topic_id(topic_id) ⇒ Object
109 110 111 |
# File 'app/models/concerns/shared/citations.rb', line 109 def sources_by_topic_id(topic_id) Source.joins(:citation_topics).where(citations: {citation_object: self}, citation_topics: {topic_id:}) end |