Class: Autoselect::TaxonName::Levels::CatalogueOfLife
Constant Summary
Constants inherited
from Level
Level::DEFAULT_FUSE_MS, Level::EXTERNAL_FUSE_MS, Level::MINIMUM_RESULTS
Instance Method Summary
collapse
#record_info, #record_info_html
Methods inherited from Level
#fuse_ms, #metadata, #minimum_results, #model_key, #record_info, #record_info_html
Instance Method Details
#call(term:, operator: nil, project_id: nil, user_id: nil, dataset_id: nil, **_kwargs) ⇒ Array<OpenStruct>
Returns pseudo-records compatible with TaxonName autoselect format_results.
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/autoselect/taxon_name/levels/catalogue_of_life.rb', line 36
def call(term:, operator: nil, project_id: nil, user_id: nil, dataset_id: nil, **_kwargs)
raw = ::Vendor::Colrapi.search(term, dataset_id:)
results = raw['result'] || []
return [] if results.empty?
results.map do |col_result|
col_name = col_result.dig('name', 'scientificName') || col_result['label']
col_rank = col_result.dig('name', 'rank')&.downcase
col_name = ::Vendor::Colrapi.(col_name) if col_rank == 'subgenus'
col_status = col_result['status']
col_key = col_result['id']
extension = ::Vendor::Colrapi.build_extension(col_result, project_id, dataset_id:)
if project_id.present?
existing = ::TaxonName.where(project_id:, cached: col_name).first
if existing
extension = extension.merge(
target_taxonworks_id: existing.id,
target_global_id: existing.to_global_id.to_s
)
end
end
extension = extension.merge(target_rank_unknown: true) unless rank_resolvable?(col_rank)
OpenStruct.new(
id: nil,
cached: col_name,
name: col_name,
rank_string: nil,
cached_valid_taxon_name_id: nil,
_col_extension: extension
)
end
end
|
#description ⇒ Object
16
17
18
|
# File 'lib/autoselect/taxon_name/levels/catalogue_of_life.rb', line 16
def description
'Search the Catalogue of Life for matching names. Returns external results with alignment data for confirmation.'
end
|
#external? ⇒ Boolean
20
21
22
|
# File 'lib/autoselect/taxon_name/levels/catalogue_of_life.rb', line 20
def external?
true
end
|
#key ⇒ Object
8
9
10
|
# File 'lib/autoselect/taxon_name/levels/catalogue_of_life.rb', line 8
def key
:catalogue_of_life
end
|
#label ⇒ Object
12
13
14
|
# File 'lib/autoselect/taxon_name/levels/catalogue_of_life.rb', line 12
def label
'Catalogue of Life'
end
|
#rank_resolvable?(rank_string) ⇒ Boolean
80
81
82
83
84
85
86
|
# File 'lib/autoselect/taxon_name/levels/catalogue_of_life.rb', line 80
def rank_resolvable?(rank_string)
return false if rank_string.blank?
r = rank_string.to_s.downcase
[:ICZN_LOOKUP, :ICN_LOOKUP, :ICNP_LOOKUP, :ICVCN_LOOKUP].any? do |key|
Object.const_get("::#{key}")[r].present?
end
end
|
#record_label(record) ⇒ Object
24
25
26
|
# File 'lib/autoselect/taxon_name/levels/catalogue_of_life.rb', line 24
def record_label(record)
record.cached.to_s
end
|
#record_label_html(record) ⇒ Object
28
29
30
|
# File 'lib/autoselect/taxon_name/levels/catalogue_of_life.rb', line 28
def record_label_html(record)
record.cached.to_s
end
|