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



80
81
82
# File 'app/models/concerns/shared/identifiers.rb', line 80

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

#identified?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'app/models/concerns/shared/identifiers.rb', line 84

def identified?
  self.identifiers.any?
end

#next_by_identifierObject



88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'app/models/concerns/shared/identifiers.rb', line 88

def next_by_identifier
  if i = identifiers.order(:position).first
    self.class
      .where(project_id: project_id)
      .where.not(id: id)
      .with_identifier_type_and_namespace_method(i.type, i.namespace_id, 'ASC')
      .where(Utilities::Strings.is_i?(i.identifier) ?
             ["CAST(identifiers.identifier AS bigint) > #{i.identifier}"] : ["identifiers.identifier > ?", i.identifier])
      .first
  else
    nil
  end
end

#previous_by_identifierObject



102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'app/models/concerns/shared/identifiers.rb', line 102

def previous_by_identifier
  if i = identifiers.order(:position).first
    self.class
      .where(project_id: project_id)
      .where.not(id: id)
      .with_identifier_type_and_namespace_method(i.type, i.namespace_id, 'DESC')
      .where(Utilities::Strings.is_i?(i.identifier) ?
             ["CAST(identifiers.identifier AS bigint) < #{i.identifier}"] : ["identifiers.identifier < ?", i.identifier])
      .first
  else
    nil
  end
end

#reject_identifiers(attributed) ⇒ Object (protected)



118
119
120
# File 'app/models/concerns/shared/identifiers.rb', line 118

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