Class: TaxonomyTerm
- Inherits:
-
Object
- Object
- TaxonomyTerm
- 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
37 38 39 |
# File 'app/models/taxonomy_term.rb', line 37 def self.find_term_by_id(term_id) where(term_id: term_id).try(:first) end |
.label_for_term(term_id) ⇒ Object
33 34 35 |
# File 'app/models/taxonomy_term.rb', line 33 def self.label_for_term(term_id) find_term_by_id(term_id).try(:label) end |
.purge! ⇒ Object
29 30 31 |
# File 'app/models/taxonomy_term.rb', line 29 def self.purge! TaxonomyTerm.destroy_all end |
Instance Method Details
#ancestor?(term) ⇒ Boolean
46 47 48 49 50 51 52 |
# File 'app/models/taxonomy_term.rb', line 46 def ancestor?(term) if(parent_term) (parent_term == term) or parent_term.ancestor?(term) else false end end |
#descendant?(term) ⇒ Boolean
54 55 56 57 58 59 |
# File 'app/models/taxonomy_term.rb', line 54 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_code ⇒ Object
42 43 44 |
# File 'app/models/taxonomy_term.rb', line 42 def fund_code term_type['FUND_CODE'] end |