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.



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

def initialize(parent)
  @parent = parent
end

Instance Attribute Details

#parentAbstractCursor (readonly)

Returns:



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

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:



96
97
98
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 96

def delete
  self
end

#depthInteger

Distance from the root node

Returns:

  • (Integer)


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

def depth
  @parent.depth + 1
end

#firstAbstractCursor

Navigate to the first (leftmost) sibling node

Returns:



75
76
77
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 75

def first
  self
end

#first?Boolean

Returns:

  • (Boolean)


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

def first?
  true
end

#lastAbstractCursor

Navigate to the last (rightmost) sibling node

Returns:



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

def last
  self
end

#last?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 50

def last?
  true
end

#leaf?Boolean

Returns:

  • (Boolean)


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

def leaf?
  true
end

#nextAbstractCursor

Navigate to the next (rightward) sibling node



63
64
65
66
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 63

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

#node#leaf?, ...

Returns:

Raises:



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

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

#pathAbstractPath

Returns:



22
23
24
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 22

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

#prevAbstractCursor

Navigate to the previous (leftward) sibling node



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

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:



88
89
90
# File 'lib/stupidedi/zipper/dangling_cursor.rb', line 88

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

#root?Boolean

Returns:

  • (Boolean)


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

def root?
  false
end

#upAbstractCursor

Returns:



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

def up
  @parent
end