Class: Qa::SubjectMeshTerm

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/qa/subject_mesh_term.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_tree_number(tree_id) ⇒ Object



4
5
6
# File 'app/models/qa/subject_mesh_term.rb', line 4

def self.from_tree_number(tree_id)
  Qa::SubjectMeshTerm.joins('INNER JOIN qa_mesh_trees ON qa_subject_mesh_terms.term_id = qa_mesh_trees.term_id').where('qa_mesh_trees.tree_number = ?', tree_id)
end

Instance Method Details

#parentsObject



26
27
28
29
# File 'app/models/qa/subject_mesh_term.rb', line 26

def parents
  t = trees
  t.map { |tn| initial_segements_of(tn) }.flatten.uniq.map { |tn| Qa::SubjectMeshTerm.from_tree_number(tn) }
end

#synonymsObject



12
13
14
15
# File 'app/models/qa/subject_mesh_term.rb', line 12

def synonyms
  s = read_attribute(:synonyms)
  s.nil? ? [] : s.split("|")
end

#synonyms=(syn_list) ⇒ Object



17
18
19
20
21
22
23
24
# File 'app/models/qa/subject_mesh_term.rb', line 17

def synonyms=(syn_list)
  write_attribute(:synonyms,
                  if syn_list.respond_to?(:join)
                    syn_list.join('|')
                  else
                    syn_list
                  end)
end

#treesObject



8
9
10
# File 'app/models/qa/subject_mesh_term.rb', line 8

def trees
  Qa::MeshTree.where(term_id: term_id).map(&:tree_number)
end