Class: Stupidedi::Zipper::RootCursor

Inherits:
AbstractCursor show all
Defined in:
lib/stupidedi/zipper/root_cursor.rb

Instance Attribute Summary collapse

Query the Tree Location collapse

Traversing the Tree collapse

Editing the Tree collapse

Instance Method Summary collapse

Methods inherited from AbstractCursor

#append_child, #between, #child, #children, #dangle, #descendant, #down, #flatten, #insert_left, #insert_right, #prepend_child

Constructor Details

#initialize(node) ⇒ RootCursor

Returns a new instance of RootCursor.



14
15
16
17
# File 'lib/stupidedi/zipper/root_cursor.rb', line 14

def initialize(node)
  @node, @path =
    node, Root
end

Instance Attribute Details

#nodeAbstractNode (readonly)

Returns:

  • (AbstractNode)


9
10
11
# File 'lib/stupidedi/zipper/root_cursor.rb', line 9

def node
  @node
end

#pathAbstractPath (readonly)

Returns:



12
13
14
# File 'lib/stupidedi/zipper/root_cursor.rb', line 12

def path
  @path
end

Instance Method Details

#append(node) ⇒ EditedCursor, void

Insert a new sibling node after (to the right of) the current node, and navigate to the new sibling node

Returns:



92
93
94
95
# File 'lib/stupidedi/zipper/root_cursor.rb', line 92

def append(node)
  raise Exceptions::ZipperError,
    "root node has no siblings"
end

#deleteEditedCursor, void

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.

Returns:



112
113
114
115
# File 'lib/stupidedi/zipper/root_cursor.rb', line 112

def delete
  raise Exceptions::ZipperError,
    "cannot delete root node"
end

#depthInteger

Distance from the root node

Returns:

  • (Integer)


23
24
25
# File 'lib/stupidedi/zipper/root_cursor.rb', line 23

def depth
  0
end

#firstAbstractCursor

Navigate to the first (leftmost) sibling node

Returns:



51
52
53
# File 'lib/stupidedi/zipper/root_cursor.rb', line 51

def first
  self
end

#first?Object



28
29
30
# File 'lib/stupidedi/zipper/root_cursor.rb', line 28

def first?
  true
end

#lastAbstractCursor

Navigate to the last (rightmost) sibling node

Returns:



56
57
58
# File 'lib/stupidedi/zipper/root_cursor.rb', line 56

def last
  self
end

#last?Object



33
34
35
# File 'lib/stupidedi/zipper/root_cursor.rb', line 33

def last?
  true
end

#leaf?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/stupidedi/zipper/root_cursor.rb', line 38

def leaf?
  @node.leaf? or @node.children.empty?
end

#nextAbstractCursor, void

Navigate to the next (rightward) sibling node

Returns:



62
63
64
65
# File 'lib/stupidedi/zipper/root_cursor.rb', line 62

def next
  raise Exceptions::ZipperError,
    "root node has no siblings"
end

#prepend(node) ⇒ EditedCursor, void

Insert a new sibling node before (to the left of) the current node, and navigate to the new sibling node

Returns:



99
100
101
102
# File 'lib/stupidedi/zipper/root_cursor.rb', line 99

def prepend(node)
  raise Exceptions::ZipperError,
    "root node has no siblings"
end

#prevAbstractCursor, void

Navigate to the previous (leftward) sibling node

Returns:



69
70
71
72
# File 'lib/stupidedi/zipper/root_cursor.rb', line 69

def prev
  raise Exceptions::ZipperError,
    "root node has no siblings"
end

#replace(node) ⇒ AbstractCursor, RootCursor

Replace the current node with the given node

Returns:



106
107
108
# File 'lib/stupidedi/zipper/root_cursor.rb', line 106

def replace(node)
  RootCursor.new(node)
end

#rootRootCursor

Navigate to the root node

Returns:



76
77
78
# File 'lib/stupidedi/zipper/root_cursor.rb', line 76

def root
  self
end

#root?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/stupidedi/zipper/root_cursor.rb', line 43

def root?
  true
end

#upAbstractCursor, void

Navigate to the parent node

Returns:



82
83
84
85
# File 'lib/stupidedi/zipper/root_cursor.rb', line 82

def up
  raise Exceptions::ZipperError,
    "root node has no parent"
end