Class: Stupidedi::Zipper::DanglingCursor

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

Instance Attribute Summary collapse

Querying 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, #root

Constructor Details

#initialize(parent) ⇒ DanglingCursor

Returns a new instance of DanglingCursor.



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

def initialize(parent)
  @parent = parent
end

Instance Attribute Details

#parentAbstractCursor (readonly)

Returns:



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

def parent
  @parent
end

Instance Method Details

#deleteEditedCursor

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:



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

def delete
  self
end

#depthInteger

Distance from the root node

Returns:



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

def depth
  @parent.depth + 1
end

#firstAbstractCursor

Navigate to the first (leftmost) sibling node

Returns:



73
74
75
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 73

def first
  self
end

#first?Boolean

Returns:

  • (Boolean)


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

def first?
  true
end

#lastAbstractCursor

Navigate to the last (rightmost) sibling node

Returns:



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

def last
  self
end

#last?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 48

def last?
  true
end

#leaf?Boolean

Returns:

  • (Boolean)


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

def leaf?
  true
end

#nextAbstractCursor

Navigate to the next (rightward) sibling node



61
62
63
64
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 61

def next
  raise Exceptions::ZipperError,
    "cannot move to next after last node"
end

#node#leaf?, ...

Returns:

Raises:



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

def node
  raise Exceptions::ZipperError,
    "DanglingCursor#node should not be called"
end

#pathAbstractPath

Returns:



20
21
22
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 20

def path
  Hole.new([], @parent.path.parent, [])
end

#prevAbstractCursor

Navigate to the previous (leftward) sibling node



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

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

Returns:



86
87
88
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 86

def replace(node)
  @parent.append_child(node)
end

#root?Boolean

Returns:

  • (Boolean)


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

def root?
  false
end

#upAbstractCursor

Returns:



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

def up
  @parent
end