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.
13 14 15 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 13 def initialize(parent) @parent = parent end |
Instance Attribute Details
#parent ⇒ AbstractCursor (readonly)
11 12 13 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 11 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.
98 99 100 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 98 def delete self end |
#depth ⇒ Integer
Distance from the root node
42 43 44 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 42 def depth @parent.depth + 1 end |
#first ⇒ AbstractCursor
Navigate to the first (leftmost) sibling node
77 78 79 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 77 def first self end |
#first? ⇒ Boolean
47 48 49 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 47 def first? true end |
#last ⇒ AbstractCursor
Navigate to the last (rightmost) sibling node
82 83 84 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 82 def last self end |
#last? ⇒ Boolean
52 53 54 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 52 def last? true end |
#leaf? ⇒ Boolean
32 33 34 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 32 def leaf? true end |
#next ⇒ AbstractCursor
Navigate to the next (rightward) sibling node
65 66 67 68 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 65 def next raise Exceptions::ZipperError, "cannot move to next after last node" end |
#node ⇒ #leaf?, ...
18 19 20 21 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 18 def node raise Exceptions::ZipperError, "DanglingCursor#node should not be called" end |
#path ⇒ AbstractPath
24 25 26 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 24 def path Hole.new([], @parent.path.parent, []) end |
#prev ⇒ AbstractCursor
Navigate to the previous (leftward) sibling node
71 72 73 74 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 71 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
90 91 92 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 90 def replace(node) @parent.append_child(node) end |
#root? ⇒ Boolean
37 38 39 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 37 def root? false end |
#up ⇒ AbstractCursor
60 61 62 |
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 60 def up @parent end |