Class: Stupidedi::Zipper::DanglingCursor
- Inherits:
-
AbstractCursor
- Object
- AbstractCursor
- Stupidedi::Zipper::DanglingCursor
- Defined in:
- lib/stupidedi/zipper/dangling_cursor.rb
Instance Attribute Summary collapse
- #parent ⇒ AbstractCursor readonly
Querying the Tree Location collapse
-
#depth ⇒ Integer
Distance from the root node.
- #first? ⇒ Boolean
- #last? ⇒ Boolean
- #leaf? ⇒ Boolean
- #root? ⇒ Boolean
Traversing the Tree collapse
-
#first ⇒ AbstractCursor
Navigate to the first (leftmost) sibling node.
-
#last ⇒ AbstractCursor
Navigate to the last (rightmost) sibling node.
-
#next ⇒ AbstractCursor
Navigate to the next (rightward) sibling node.
-
#prev ⇒ AbstractCursor
Navigate to the previous (leftward) sibling node.
- #up ⇒ AbstractCursor
Editing the Tree collapse
-
#delete ⇒ EditedCursor
Remove the current node, and navigate to the next (rightward) node if one exists.
-
#replace(node) ⇒ AbstractCursor
(also: #prepend, #append)
Replace the current node with the given node.
Instance Method Summary collapse
-
#initialize(parent) ⇒ DanglingCursor
constructor
A new instance of DanglingCursor.
- #node ⇒ #leaf?, ...
- #path ⇒ AbstractPath
Methods inherited from AbstractCursor
#append_child, #between, #child, #children, #dangle, #descendant, #down, #flatten, #insert_left, #insert_right, #prepend_child, #root
Constructor Details
#initialize(parent) ⇒ DanglingCursor
Returns a new instance of DanglingCursor.
11 12 13 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 11 def initialize(parent) @parent = parent end |
Instance Attribute Details
#parent ⇒ AbstractCursor (readonly)
9 10 11 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 9 def parent @parent end |
Instance Method Details
#delete ⇒ EditedCursor
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.
96 97 98 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 96 def delete self end |
#depth ⇒ Integer
Distance from the root node
40 41 42 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 40 def depth @parent.depth + 1 end |
#first ⇒ AbstractCursor
Navigate to the first (leftmost) sibling node
75 76 77 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 75 def first self end |
#first? ⇒ Boolean
45 46 47 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 45 def first? true end |
#last ⇒ AbstractCursor
Navigate to the last (rightmost) sibling node
80 81 82 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 80 def last self end |
#last? ⇒ Boolean
50 51 52 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 50 def last? true end |
#leaf? ⇒ Boolean
30 31 32 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 30 def leaf? true end |
#next ⇒ AbstractCursor
Navigate to the next (rightward) sibling node
63 64 65 66 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 63 def next raise Exceptions::ZipperError, "cannot move to next after last node" end |
#node ⇒ #leaf?, ...
16 17 18 19 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 16 def node raise Exceptions::ZipperError, "DanglingCursor#node should not be called" end |
#path ⇒ AbstractPath
22 23 24 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 22 def path Hole.new([], @parent.path.parent, []) end |
#prev ⇒ AbstractCursor
Navigate to the previous (leftward) sibling node
69 70 71 72 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 69 def prev raise Exceptions::ZipperError, "cannot move to prev before first node" end |
#replace(node) ⇒ AbstractCursor Also known as: prepend, append
Replace the current node with the given node
88 89 90 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 88 def replace(node) @parent.append_child(node) end |
#root? ⇒ Boolean
35 36 37 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 35 def root? false end |
#up ⇒ AbstractCursor
58 59 60 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 58 def up @parent end |