Class: Qa::MeshTree

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.classify_all_treesObject



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

def self.classify_all_trees
  MeshTreeStructure.find_each(&:classify_tree!)
end

Instance Method Details

#classify_treeObject



13
14
15
16
# File 'app/models/qa/mesh_tree.rb', line 13

def classify_tree
  tree_levels = initial_segements_of(tree_structure)
  tree_levels.map(&:lookup_tree_term)
end

#classify_tree!Object



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

def classify_tree!
  unless classify_tree.empty? # rubocop:disable Style/GuardClause
    tree_path = classify_tree.join('|')
    Rails.logger.info "After Join #{tree_path.inspect}"
    update_attribute(:eval_tree_path, tree_path) # rubocop:disable Rails/SkipsModelValidations # TODO: Explore how to avoid use of update_attribute.
  end
end

#eval_tree_pathObject



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

def eval_tree_path
  trees = self[:eval_tree_path] || (self[:eval_tree_path] = "")
  trees ? trees.split("|") : []
end

#lookup_tree_term(tree_id) ⇒ Object

given a tree id, return the main subject term e.g. ‘C03.752.530’ returns ‘Malaria’



28
29
30
# File 'app/models/qa/mesh_tree.rb', line 28

def lookup_tree_term(tree_id)
  self.class.get_term(tree_id).first.term
end