Sha256: 2b52fdfa242fc11e6a0e247e60e02a323742e06bc1a226fb9abfa62272c51321

Contents?: true

Size: 990 Bytes

Versions: 37

Compression:

Stored size: 990 Bytes

Contents

class Qa::MeshTree < ActiveRecord::Base
  belongs_to :subject_mesh_term, foreign_key: "term_id", primary_key: 'term_id'

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

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

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

  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

  # given a tree id, return the main subject term
  # e.g. 'C03.752.530' returns 'Malaria'
  def lookup_tree_term(tree_id)
    self.class.get_term(tree_id).first.term
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
qa-5.14.0 app/models/qa/mesh_tree.rb
qa-5.13.0 app/models/qa/mesh_tree.rb
qa-5.12.0 app/models/qa/mesh_tree.rb
qa-5.11.0 app/models/qa/mesh_tree.rb
qa-5.10.0 app/models/qa/mesh_tree.rb
qa-5.9.0 app/models/qa/mesh_tree.rb
qa-5.8.1 app/models/qa/mesh_tree.rb
qa-5.8.0 app/models/qa/mesh_tree.rb
qa-5.7.0 app/models/qa/mesh_tree.rb
qa-5.6.0 app/models/qa/mesh_tree.rb
qa-5.5.2 app/models/qa/mesh_tree.rb
qa-4.3.0 app/models/qa/mesh_tree.rb
qa-3.1.0 app/models/qa/mesh_tree.rb
qa-2.3.0 app/models/qa/mesh_tree.rb
qa-5.5.1 app/models/qa/mesh_tree.rb
qa-5.5.0 app/models/qa/mesh_tree.rb
qa-5.4.0 app/models/qa/mesh_tree.rb
qa-5.3.1 app/models/qa/mesh_tree.rb
qa-5.3.0 app/models/qa/mesh_tree.rb
qa-5.2.0 app/models/qa/mesh_tree.rb