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.



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

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

Instance Attribute Details

#nodeAbstractNode (readonly)

Returns:

  • (AbstractNode)


7
8
9
# File 'lib/stupidedi/zipper/root_cursor.rb', line 7

def node
  @node
end

#pathAbstractPath (readonly)

Returns:



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

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:



90
91
92
93
# File 'lib/stupidedi/zipper/root_cursor.rb', line 90

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:



110
111
112
113
# File 'lib/stupidedi/zipper/root_cursor.rb', line 110

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

#depthInteger

Distance from the root node

Returns:



21
22
23
# File 'lib/stupidedi/zipper/root_cursor.rb', line 21

def depth
  0
end

#firstAbstractCursor

Navigate to the first (leftmost) sibling node

Returns:



49
50
51
# File 'lib/stupidedi/zipper/root_cursor.rb', line 49

def first
  self
end

#first?Object



26
27
28
# File 'lib/stupidedi/zipper/root_cursor.rb', line 26

def first?
  true
end

#lastAbstractCursor

Navigate to the last (rightmost) sibling node

Returns:



54
55
56
# File 'lib/stupidedi/zipper/root_cursor.rb', line 54

def last
  self
end

#last?Object



31
32
33
# File 'lib/stupidedi/zipper/root_cursor.rb', line 31

def last?
  true
end

#leaf?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/stupidedi/zipper/root_cursor.rb', line 36

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

#nextAbstractCursor, void

Navigate to the next (rightward) sibling node

Returns:



60
61
62
63
# File 'lib/stupidedi/zipper/root_cursor.rb', line 60

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:



97
98
99
100
# File 'lib/stupidedi/zipper/root_cursor.rb', line 97

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

#prevAbstractCursor, void

Navigate to the previous (leftward) sibling node

Returns:



67
68
69
70
# File 'lib/stupidedi/zipper/root_cursor.rb', line 67

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

#replace(node) ⇒ AbstractCursor, RootCursor

Replace the current node with the given node

Returns:



104
105
106
# File 'lib/stupidedi/zipper/root_cursor.rb', line 104

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

#rootRootCursor

Navigate to the root node

Returns:



74
75
76
# File 'lib/stupidedi/zipper/root_cursor.rb', line 74

def root
  self
end

#root?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/stupidedi/zipper/root_cursor.rb', line 41

def root?
  true
end

#upAbstractCursor, void

Navigate to the parent node

Returns:



80
81
82
83
# File 'lib/stupidedi/zipper/root_cursor.rb', line 80

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