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.



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

def initialize(parent)
  @parent = parent
end

Instance Attribute Details

#parentAbstractCursor (readonly)

Returns:



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

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:



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

def delete
  self
end

#depthInteger

Distance from the root node

Returns:



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

def depth
  @parent.depth + 1
end

#firstAbstractCursor

Navigate to the first (leftmost) sibling node

Returns:



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

def first
  self
end

#first?Boolean

Returns:

  • (Boolean)


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

def first?
  true
end

#lastAbstractCursor

Navigate to the last (rightmost) sibling node

Returns:



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

def last
  self
end

#last?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 52

def last?
  true
end

#leaf?Boolean

Returns:

  • (Boolean)


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

def leaf?
  true
end

#nextAbstractCursor

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?, ...

Returns:

Raises:



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

#pathAbstractPath

Returns:



24
25
26
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 24

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

#prevAbstractCursor

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

Returns:



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

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

#root?Boolean

Returns:

  • (Boolean)


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

def root?
  false
end

#upAbstractCursor

Returns:



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

def up
  @parent
end