Module: Shared::Identifiers

Overview

Shared code for objects that have Identifiers.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#dwc_occurrence_idObject



94
95
96
# File 'app/models/concerns/shared/identifiers.rb', line 94

def dwc_occurrence_id
  identifiers.where('identifiers.type like ?', 'Identifier::Global::Uuid%').order('identifiers.position ASC').first&.identifier
end

#identified?Boolean

Returns:

  • (Boolean)


98
99
100
101
102
103
104
# File 'app/models/concerns/shared/identifiers.rb', line 98

def identified?
  if respond_to?(:project_id)
    identifiers.visible(self.project_id).any?
  else
    identifiers.any?
  end
end

#next_by_identifierObject



106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'app/models/concerns/shared/identifiers.rb', line 106

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_identifierObject



121
122
123
124
125
126
127
128
129
130
131
132
# File 'app/models/concerns/shared/identifiers.rb', line 121

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)



136
137
138
# File 'app/models/concerns/shared/identifiers.rb', line 136

def reject_identifiers(attributed)
  attributed['identifier'].blank? || attributed['type'].blank?
end

#uriObject



86
87
88
# File 'app/models/concerns/shared/identifiers.rb', line 86

def uri
  uris.first&.cached
end

#uuidObject



90
91
92
# File 'app/models/concerns/shared/identifiers.rb', line 90

def uuid
  uuids.first&.cached
end