Module: Shared::Citations

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

Instance Method Details

#cited?Boolean

Returns:

  • (Boolean)


142
143
144
# File 'app/models/concerns/shared/citations.rb', line 142

def cited?
  self.citations.any?
end

#mark_citations_for_destructionObject



146
147
148
# File 'app/models/concerns/shared/citations.rb', line 146

def mark_citations_for_destruction
  citations.map(&:mark_for_destruction)
end

#nomenclature_dateTime?

See Source::Bibtex for context !! Over-riden in various places.

Returns:

  • (Time, nil)


120
121
122
123
124
# File 'app/models/concerns/shared/citations.rb', line 120

def nomenclature_date
  if source && source.is_bibtex?
    source.nomenclature_date
  end
end

#origin_citation_source_idObject



126
127
128
129
130
# File 'app/models/concerns/shared/citations.rb', line 126

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)



152
153
154
155
156
157
158
# File 'app/models/concerns/shared/citations.rb', line 152

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.

Returns:

  • (Boolean)

    if at least one citation is required override this with true in including class



138
139
140
# File 'app/models/concerns/shared/citations.rb', line 138

def requires_citation?
  false
end

#sources_by_topic_id(topic_id) ⇒ Object



132
133
134
# File 'app/models/concerns/shared/citations.rb', line 132

def sources_by_topic_id(topic_id)
  Source.joins(:citation_topics).where(citations: {citation_object: self}, citation_topics: {topic_id: topic_id}) 
end