Class: Stupidedi::Zipper::DanglingCursor
- Inherits:
-
AbstractCursor
- Object
- AbstractCursor
- Stupidedi::Zipper::DanglingCursor
- Defined in:
- lib/stupidedi/zipper/dangling_cursor.rb
Instance Attribute Summary (collapse)
- - (AbstractCursor) parent readonly
Querying the Tree Location (collapse)
-
- (Integer) depth
Distance from the root node.
- - (Boolean) first?
- - (Boolean) last?
- - (Boolean) leaf?
- - (Boolean) root?
Traversing the Tree (collapse)
-
- (AbstractCursor) first
Navigate to the first (leftmost) sibling node.
-
- (AbstractCursor) last
Navigate to the last (rightmost) sibling node.
-
- (AbstractCursor) next
Navigate to the next (rightward) sibling node.
-
- (AbstractCursor) prev
Navigate to the previous (leftward) sibling node.
- - (AbstractCursor) up
Editing the Tree (collapse)
-
- (EditedCursor) delete
Remove the current node, and navigate to the next (rightward) node if one exists.
-
- (AbstractCursor) replace(node)
(also: #prepend, #append)
Replace the current node with the given node.
Instance Method Summary (collapse)
-
- (DanglingCursor) initialize(parent)
constructor
A new instance of DanglingCursor.
- - (#leaf?, ...) node
- - (AbstractPath) path
Methods inherited from AbstractCursor
#append_child, #between, #child, #children, #dangle, #descendant, #down, #flatten, #insert_left, #insert_right, #prepend_child, #root
Constructor Details
- (DanglingCursor) initialize(parent)
A new instance of DanglingCursor
9 10 11 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 9 def initialize(parent) @parent = parent end |
Instance Attribute Details
- (AbstractCursor) parent (readonly)
7 8 9 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 7 def parent @parent end |
Instance Method Details
- (EditedCursor) delete
Remove the current node, and navigate to the next (rightward) node if one exists. Otherwise, navigate to the previous (leftward) node if one exists. Otherwise, create a placeholder where the next sibling node will be created.
94 95 96 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 94 def delete self end |
- (Integer) depth
Distance from the root node
38 39 40 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 38 def depth @parent.depth + 1 end |
- (AbstractCursor) first
Navigate to the first (leftmost) sibling node
73 74 75 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 73 def first self end |
- (Boolean) first?
43 44 45 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 43 def first? true end |
- (AbstractCursor) last
Navigate to the last (rightmost) sibling node
78 79 80 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 78 def last self end |
- (Boolean) last?
48 49 50 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 48 def last? true end |
- (Boolean) leaf?
28 29 30 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 28 def leaf? true end |
- (AbstractCursor) next
Navigate to the next (rightward) sibling node
61 62 63 64 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 61 def next raise Exceptions::ZipperError, "cannot move to next after last node" end |
- (#leaf?, ...) node
14 15 16 17 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 14 def node raise Exceptions::ZipperError, "DanglingCursor#node should not be called" end |
- (AbstractPath) path
20 21 22 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 20 def path Hole.new([], @parent.path.parent, []) end |
- (AbstractCursor) prev
Navigate to the previous (leftward) sibling node
67 68 69 70 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 67 def prev raise Exceptions::ZipperError, "cannot move to prev before first node" end |
- (AbstractCursor) replace(node) Also known as: prepend, append
Replace the current node with the given node
86 87 88 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 86 def replace(node) @parent.append_child(node) end |
- (Boolean) root?
33 34 35 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 33 def root? false end |
- (AbstractCursor) up
56 57 58 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 56 def up @parent end |