5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/labimotion/libs/template_matcher.rb', line 5
def self.find_best_match(ols_term_id)
return { template: nil, match_type: nil, info_messages: [] } if ols_term_id.blank?
info_messages = []
assigned = Labimotion::DatasetKlass.find_assigned_templates(ols_term_id)
if assigned.any?
handle_multiple_results(assigned, :assigned, info_messages)
return { template: assigned.first, match_type: 'assigned', info_messages: info_messages }
end
exact = Labimotion::DatasetKlass.find_by(ols_term_id: ols_term_id)
return { template: exact, match_type: 'exact', info_messages: info_messages } if exact
info_messages << 'Using parent template'
inferred = Labimotion::DatasetKlass.find_inferred_templates(ols_term_id)
if inferred.any?
handle_multiple_results(inferred, :inferred, info_messages)
return { template: inferred.first, match_type: 'inferred', info_messages: info_messages }
end
{ template: nil, match_type: nil, info_messages: info_messages }
end
|