Class: OrderTree::OrderTreeNode
- Inherits:
-
UniqueProxy
- Object
- UniqueProxy
- OrderTree::OrderTreeNode
- Defined in:
- lib/order_tree/order_tree_node.rb
Instance Attribute Summary collapse
-
#next ⇒ Object
Returns the value of attribute next.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#prev ⇒ Object
Returns the value of attribute prev.
-
#tree ⇒ Object
Returns the value of attribute tree.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #after(other) ⇒ Object
- #before(other) ⇒ Object
- #deproxy ⇒ Object
-
#initialize(obj, tree) ⇒ OrderTreeNode
constructor
A new instance of OrderTreeNode.
- #path! ⇒ Object
- #remove ⇒ Object
Methods inherited from UniqueProxy
#!, #!=, #==, #equal?, #inspect, #method_missing, #orig, #to_s, #unique_id
Constructor Details
#initialize(obj, tree) ⇒ OrderTreeNode
Returns a new instance of OrderTreeNode.
7 8 9 10 |
# File 'lib/order_tree/order_tree_node.rb', line 7 def initialize obj, tree super(obj) @tree = tree end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class OrderTree::UniqueProxy
Instance Attribute Details
#next ⇒ Object
Returns the value of attribute next.
3 4 5 |
# File 'lib/order_tree/order_tree_node.rb', line 3 def next @next end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/order_tree/order_tree_node.rb', line 5 def path @path end |
#prev ⇒ Object
Returns the value of attribute prev.
3 4 5 |
# File 'lib/order_tree/order_tree_node.rb', line 3 def prev @prev end |
#tree ⇒ Object
Returns the value of attribute tree.
4 5 6 |
# File 'lib/order_tree/order_tree_node.rb', line 4 def tree @tree end |
Instance Method Details
#<=>(other) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/order_tree/order_tree_node.rb', line 64 def <=> other if self.equal? other return 0 else p, n = self.prev, self.next while p or n return 1 if p.equal? other return -1 if n.equal? other p = p.prev if p n = n.next if n end end raise ::ArgumentError, "Cannot compare #{self} and #{other} because they are not in the same tree" end |
#after(other) ⇒ Object
60 61 62 |
# File 'lib/order_tree/order_tree_node.rb', line 60 def after other (self <=> other) == 1 ? true : false end |
#before(other) ⇒ Object
56 57 58 |
# File 'lib/order_tree/order_tree_node.rb', line 56 def before other (self <=> other) == -1 ? true : false end |
#deproxy ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/order_tree/order_tree_node.rb', line 47 def deproxy orig = self.orig.respond_to?(:dup) ? self.orig.dup : self.orig if orig.respond_to? :each orig.each.map! { |i| proxy?(i) ? i.deproxy : i } end orig end |
#path! ⇒ Object
83 84 85 |
# File 'lib/order_tree/order_tree_node.rb', line 83 def path! @path = self.tree.root.strict_path! self end |
#remove ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/order_tree/order_tree_node.rb', line 12 def remove prev_node = self.prev next_node = self.next self.next.prev = prev_node if self.next self.prev.next = next_node if self.prev if self.tree.root.first.equal? self if next_node self.tree.root.instance_eval do self.first = next_node end end end if self.tree.root.last.equal? self if prev_node self.tree.root.instance_eval do self.last = prev_node end end end # try this so that the node can remove # itself fromt he tree my_path = self.path self.tree.instance_eval do _delegate_hash.delete my_path.last end @path = nil @tree = nil @next = nil @prev = nil self end |