Class: Qa::Authorities::Mesh

Inherits:
Base
  • Object
show all
Defined in:
lib/qa/authorities/mesh.rb

Instance Attribute Summary

Attributes inherited from Base

#sub_authority

Instance Method Summary collapse

Methods inherited from Base

#full_record, #initialize, #sub_authorities

Constructor Details

This class inherits a constructor from Qa::Authorities::Base

Instance Method Details

#allObject



18
19
20
21
22
23
# File 'lib/qa/authorities/mesh.rb', line 18

def all
  begin
    r = Qa::SubjectMeshTerm.all
    r.map { |t| {id: t.term_id, label: t.term} }
  end
end

#find(id) ⇒ Object



11
12
13
14
15
16
# File 'lib/qa/authorities/mesh.rb', line 11

def find id
  begin
    r = Qa::SubjectMeshTerm.where(term_id: id).limit(1).first
    r.nil? ? nil : {id: r.term_id, label: r.term, synonyms: r.synonyms}
  end
end

#search(q) ⇒ Object



4
5
6
7
8
9
# File 'lib/qa/authorities/mesh.rb', line 4

def search q
  begin
    r = Qa::SubjectMeshTerm.where('term_lower LIKE ?', "#{@q}%").limit(10)
    r.map { |t| {id: t.term_id, label: t.term} }
  end
end