Class: Identifier::Global::Uri::ChecklistBank

Inherits:
Identifier::Global::Uri show all
Defined in:
app/models/identifier/global/uri/checklist_bank.rb

Overview

For example https://api.checklistbank.org/dataset/9802/taxon/1000027.

This has properties that blur into Namespace, we could think of Datasets as Namespaces. It is also somewhat hybrid conceptually in that while Global it doesn't have the same rigour as in definition, broadness, etc.

!! Neither of dataset_id and taxon_id need be integers.

Constant Summary collapse

API_ROOT =
'https://api.checklistbank.org'
VALID_ROOTS =
%w{
  https://www.checklistbank.org
  http://api.checklistbank.org
} + [API_ROOT]

Constants included from SoftValidation

SoftValidation::ANCESTORS_WITH_SOFT_VALIDATIONS

Instance Attribute Summary collapse

Attributes inherited from Identifier::Global

#relation

Instance Method Summary collapse

Methods included from Shared::Uri

#uri_attribute, #valid_uri

Methods inherited from Identifier::Global

#build_cached, #dwc_occurrences, #is_global?, #sv_resolves?

Methods included from SoftValidation

#clear_soft_validations, #fix_for, #fix_soft_validations, #soft_fixed?, #soft_valid?, #soft_validate, #soft_validated?, #soft_validations, #soft_validators

Instance Attribute Details

#dataset_idObject



28
29
30
# File 'app/models/identifier/global/uri/checklist_bank.rb', line 28

def dataset_id
  @dataset_id || identifier&.split('/')&.fetch(4, nil)
end

#taxon_idObject



32
33
34
# File 'app/models/identifier/global/uri/checklist_bank.rb', line 32

def taxon_id
  @taxon_id || identifier&.split('/')&.fetch(6, nil)
end

Instance Method Details

#api_formatObject



24
25
26
# File 'app/models/identifier/global/uri/checklist_bank.rb', line 24

def api_format
  [API_ROOT, 'dataset', dataset_id , 'taxon', taxon_id ].join('/')
end

#path_formatObject (protected)



42
43
44
# File 'app/models/identifier/global/uri/checklist_bank.rb', line 42

def path_format
  errors.add(:identifier) unless identifier.match(/dataset\/.+\/taxon\/.+$/)
end

#references_a_known_formObject (protected)



46
47
48
# File 'app/models/identifier/global/uri/checklist_bank.rb', line 46

def references_a_known_form
  errors.add(:identifier, "Must start with one of #{VALID_ROOTS.join(', ')}.") if !(identifier =~ /^#{VALID_ROOTS.join('|')}/)
end

#set_identifierObject (protected)



38
39
40
# File 'app/models/identifier/global/uri/checklist_bank.rb', line 38

def set_identifier
  self.identifier = [API_ROOT, 'dataset', @dataset_id, 'taxon', @taxon_id].join('/')
end

#used_on_taxon_name_or_otuObject (protected)



50
51
52
53
54
# File 'app/models/identifier/global/uri/checklist_bank.rb', line 50

def used_on_taxon_name_or_otu
   if !%w{TaxonName Otu}.include?(identifier_object_type)
     errors.add(:identifier_object_type, 'ChecklistBank identifiers may only be used on TaxonNames or Otus')
   end
end