Class: TaxonomyTerm

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
app/models/taxonomy_term.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_term_by_id(term_id) ⇒ Object



33
34
35
# File 'app/models/taxonomy_term.rb', line 33

def self.find_term_by_id(term_id)
 self.term_id_is(term_id).try(:first)
end

.label_for_term(term_id) ⇒ Object



29
30
31
# File 'app/models/taxonomy_term.rb', line 29

def self.label_for_term(term_id)
  where(term_id: term_id).try(:first).try(:label) if term_id
end

.purge!Object



25
26
27
# File 'app/models/taxonomy_term.rb', line 25

def self.purge!
  TaxonomyTerm.destroy_all
end

Instance Method Details

#ancestor?(term) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
45
46
47
# File 'app/models/taxonomy_term.rb', line 41

def ancestor?(term)
  if(parent_term)
    (parent_term == term) or parent_term.ancestor?(term)
  else
    false
  end
end

#descendant?(term) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
52
53
54
# File 'app/models/taxonomy_term.rb', line 49

def descendant?(term)
  # accept either an ID string or a term
  term_id = term.is_a?(String) ? term : term.try(:term_id)
  # loop thru child terms and look for the id
  child_term_ids.index(term_id) or child_terms.detect {|c| c.descendant? term_id }
end

#fund_codeObject



37
38
39
# File 'app/models/taxonomy_term.rb', line 37

def fund_code
  term_type['FUND_CODE']
end