Class: Fr::SZipper::HeadPrevCursor

Inherits:
AbstractCursor show all
Defined in:
lib/fr/szipper/head_prev_cursor.rb

Instance Method Summary collapse

Methods included from Enumerable

#all?, #any?, #chunk, #collect, #collect_concat, #count, #cycle, #detect, #drop, #drop_while, #each, #entries, #filter, #filter_, #first, #flat_map, #foldl, #grep, #group_by, #include?, #index, #max, #max_by, #min, #min_by, #minmax, #minmax_by, #none?, #partition, #reduce, #reject, #sort, #take, #take_while, #zip

Constructor Details

#initialize(node) ⇒ HeadPrevCursor

Returns a new instance of HeadPrevCursor.



5
6
7
# File 'lib/fr/szipper/head_prev_cursor.rb', line 5

def initialize(node)
  @node = node
end

Instance Method Details

#==(other) ⇒ Object



105
106
107
108
# File 'lib/fr/szipper/head_prev_cursor.rb', line 105

def ==(other)
  HeadPrevCursor === other and
  not empty? ^ other.empty?
end

#append(node) ⇒ Object



65
66
67
# File 'lib/fr/szipper/head_prev_cursor.rb', line 65

def append(node)
  HeadCursor.new(node.copy(next: @node))
end

#deleteObject



85
86
87
88
89
90
91
# File 'lib/fr/szipper/head_prev_cursor.rb', line 85

def delete
  if tail?
    self
  else
    HeadCursor.new(@node)
  end
end

#empty?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/fr/szipper/head_prev_cursor.rb', line 21

def empty?
  @node.nil?
end

#headObject



25
26
27
28
29
30
31
32
# File 'lib/fr/szipper/head_prev_cursor.rb', line 25

def head
  if @node.nil?
    raise Errors::ZipperError,
      "head.prev has no head"
  else
    HeadCursor.new(@node)
  end
end

#head?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/fr/szipper/head_prev_cursor.rb', line 13

def head?
  @node.nil?
end

#inspectObject



97
98
99
100
101
102
103
# File 'lib/fr/szipper/head_prev_cursor.rb', line 97

def inspect
  if tail?
    "Cursor([___])"
  else
    "Cursor([___, #{@node.inspect}, ...])"
  end
end

#next(phantom = false) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/fr/szipper/head_prev_cursor.rb', line 52

def next(phantom = false)
  if tail?
    if phantom
      self
    else
      raise Errors::ZipperError,
        "head.prev has no next"
    end
  else
    HeadCursor.new(@node)
  end
end

#positionObject



9
10
11
# File 'lib/fr/szipper/head_prev_cursor.rb', line 9

def position
  -1
end

#prepend(node) ⇒ Object



69
70
71
# File 'lib/fr/szipper/head_prev_cursor.rb', line 69

def prepend(node)
  HeadCursor.new(node.copy(next: @node))
end

#prev(phantom = false) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/fr/szipper/head_prev_cursor.rb', line 43

def prev(phantom = false)
  if phantom
    self
  else
    raise Errors::ZipperError,
      "head.prev has no prev"
  end
end

#replace(node) ⇒ Object



81
82
83
# File 'lib/fr/szipper/head_prev_cursor.rb', line 81

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

#tailObject



34
35
36
37
38
39
40
41
# File 'lib/fr/szipper/head_prev_cursor.rb', line 34

def tail
  if @node.nil?
    raise Errors::ZipperError,
      "head.prev has no tail"
  else
    HeadCursor.new(@node).tail
  end
end

#tail?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/fr/szipper/head_prev_cursor.rb', line 17

def tail?
  @node.nil?
end

#truncateObject



93
94
95
# File 'lib/fr/szipper/head_prev_cursor.rb', line 93

def truncate
  HeadPrevCursor.new(nil)
end

#update(node = nil) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/fr/szipper/head_prev_cursor.rb', line 73

def update(node = nil)
  if node.nil?
    HeadCursor.new(yield(nil).copy(next: @node))
  else
    HeadCursor.new(node.copy(next: @node))
  end
end