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.



16
17
18
19
# File 'lib/stupidedi/zipper/root_cursor.rb', line 16

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

Instance Attribute Details

#nodeAbstractNode (readonly)

Returns:

  • (AbstractNode)


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

def node
  @node
end

#pathAbstractPath (readonly)

Returns:



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

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:



94
95
96
97
# File 'lib/stupidedi/zipper/root_cursor.rb', line 94

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:



114
115
116
117
# File 'lib/stupidedi/zipper/root_cursor.rb', line 114

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

#depthInteger

Distance from the root node

Returns:

  • (Integer)


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

def depth
  0
end

#firstAbstractCursor

Navigate to the first (leftmost) sibling node

Returns:



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

def first
  self
end

#first?Object



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

def first?
  true
end

#lastAbstractCursor

Navigate to the last (rightmost) sibling node

Returns:



58
59
60
# File 'lib/stupidedi/zipper/root_cursor.rb', line 58

def last
  self
end

#last?Object



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

def last?
  true
end

#leaf?Boolean

Returns:

  • (Boolean)


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

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

#nextAbstractCursor, void

Navigate to the next (rightward) sibling node

Returns:



64
65
66
67
# File 'lib/stupidedi/zipper/root_cursor.rb', line 64

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:



101
102
103
104
# File 'lib/stupidedi/zipper/root_cursor.rb', line 101

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

#prevAbstractCursor, void

Navigate to the previous (leftward) sibling node

Returns:



71
72
73
74
# File 'lib/stupidedi/zipper/root_cursor.rb', line 71

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

#replace(node) ⇒ AbstractCursor, RootCursor

Replace the current node with the given node

Returns:



108
109
110
# File 'lib/stupidedi/zipper/root_cursor.rb', line 108

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

#rootRootCursor

Navigate to the root node

Returns:



78
79
80
# File 'lib/stupidedi/zipper/root_cursor.rb', line 78

def root
  self
end

#root?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/stupidedi/zipper/root_cursor.rb', line 45

def root?
  true
end

#upAbstractCursor, void

Navigate to the parent node

Returns:



84
85
86
87
# File 'lib/stupidedi/zipper/root_cursor.rb', line 84

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