Class: Taxonomite::Node
- Inherits:
-
Object
- Object
- Taxonomite::Node
- Extended by:
- ConfiguredGlobally
- Defined in:
- lib/taxonomite/node.rb
Overview
Class which defines a node within a tree hierarchy. Validation on addition of children and parents does occur in this class to provide for class specific validation in subclasses. That said, enforcing a taxonomy (rules about how the hierarchy is constructed) falls to the Taxonomite::Taxonomy class which is used to join parents and children according to specified rules. Thus, if someone does Obj.children << node – no special validation will occur, other than that provided within this class or subclasses via is_valid_child? and is_valid_parent?
Instance Method Summary collapse
-
#add_child(child) ⇒ Object
add a child to this object; default is that each parent may have many children; this will validate the child using thetaxonomy object passed in to the field.
-
#add_parent(parent) ⇒ Object
add a parent for this object (default is that each object can have only one parent).
-
#evaluate(m) ⇒ Object
evaluate a method on the owner of this node (if present).
-
#is_valid_child?(child) ⇒ Boolean
determine whether child is a valid child based upon class evalution (outside of a taxonomy).
-
#is_valid_parent?(child) ⇒ Boolean
determine whether parent is a valid parent based upon class evalution (outside of a taxonomy).
-
#remove_child(child) ⇒ Object
remove a child from this node.
-
#remove_parent ⇒ Object
remove the parent from this node.
-
#typeifiedname ⇒ String
typeify name w entity (i.e. ‘Washington state’ vs. ‘Seattle’).
Methods included from ConfiguredGlobally
Instance Method Details
#add_child(child) ⇒ Object
add a child to this object; default is that each parent may have many children; this will validate the child using thetaxonomy object passed in to the field.
87 88 89 |
# File 'lib/taxonomite/node.rb', line 87 def add_child(child) self.children << child end |
#add_parent(parent) ⇒ Object
add a parent for this object (default is that each object can have only one parent). this will validate the child using the taxonomy object passed in to the field.
97 98 99 |
# File 'lib/taxonomite/node.rb', line 97 def add_parent(parent) parent.add_child(self) end |
#evaluate(m) ⇒ Object
evaluate a method on the owner of this node (if present). If an owner is not present, then the method is evaluated on this object. In either case a check is made to ensure that the object will respond_to? the method call. If the owner exists but does not respond to the method, then the method is tried on this node object in similar fashion. !!! SHOULD THIS JUST OVERRIDE instance_eval ??
48 49 50 51 52 |
# File 'lib/taxonomite/node.rb', line 48 def evaluate(m) return self.owner.instance_eval(m) if self.owner != nil && self.owner.respond_to?(m) return self.instance_eval(m) if self.respond_to?(m) nil end |
#is_valid_child?(child) ⇒ Boolean
determine whether child is a valid child based upon class evalution (outside of a taxonomy). Default is always true - subclasses should override if validation outside of a separate taxonomy class is desired.
69 70 71 |
# File 'lib/taxonomite/node.rb', line 69 def is_valid_child?(child) return true end |
#is_valid_parent?(child) ⇒ Boolean
determine whether parent is a valid parent based upon class evalution (outside of a taxonomy). Default is always true - subclasses should override if validation outside of a separate taxonomy class is desired.
79 80 81 |
# File 'lib/taxonomite/node.rb', line 79 def is_valid_parent?(child) return true end |
#remove_child(child) ⇒ Object
remove a child from this node.
104 105 106 |
# File 'lib/taxonomite/node.rb', line 104 def remove_child(child) self.children.delete(child) end |
#remove_parent ⇒ Object
remove the parent from this node. This should cause a reciprocal removal of self from the parent’s children
111 112 113 |
# File 'lib/taxonomite/node.rb', line 111 def remove_parent self.parent.remove_child(self) unless self.parent.nil? end |
#typeifiedname ⇒ String
typeify name w entity (i.e. ‘Washington state’ vs. ‘Seattle’)
57 58 59 60 61 |
# File 'lib/taxonomite/node.rb', line 57 def typeifiedname s = self.name s += (" " + self.entity_type.capitalize) if self.includetypeinname? return s end |