Class: Command::Results::ListItem

Inherits:
Object
  • Object
show all
Defined in:
lib/command-set/result-list.rb

Overview

The root class of the List class family. A compositable tree, iterated by ListIterator.

Direct Known Subclasses

List, ListEnd

Defined Under Namespace

Classes: Exception, NoMatch

Constant Summary collapse

@@next_seq =
0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ ListItem

Returns a new instance of ListItem.



10
11
12
13
14
15
16
17
# File 'lib/command-set/result-list.rb', line 10

def initialize(value)
  @sequence = (@@next_seq +=1)
  @value = value
  @order = nil
  @parent = nil
  @options = {}
  @depth = nil
end

Instance Attribute Details

#depthObject

Returns the value of attribute depth.



20
21
22
# File 'lib/command-set/result-list.rb', line 20

def depth
  @depth
end

#optionsObject

Returns the value of attribute options.



20
21
22
# File 'lib/command-set/result-list.rb', line 20

def options
  @options
end

#orderObject

Returns the value of attribute order.



20
21
22
# File 'lib/command-set/result-list.rb', line 20

def order
  @order
end

#parentObject

Returns the value of attribute parent.



20
21
22
# File 'lib/command-set/result-list.rb', line 20

def parent
  @parent
end

#sequenceObject (readonly)

Returns the value of attribute sequence.



19
20
21
# File 'lib/command-set/result-list.rb', line 19

def sequence
  @sequence
end

#valueObject (readonly)

Returns the value of attribute value.



19
20
21
# File 'lib/command-set/result-list.rb', line 19

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



22
23
24
25
# File 'lib/command-set/result-list.rb', line 22

def ==(other)
  return (ListItem === other && 
          value == other.value)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/command-set/result-list.rb', line 44

def eql?(other)
  return self == other
end

#filter(path) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/command-set/result-list.rb', line 67

def filter(path)
  if path.empty? || path == [:**]
    return self
  else
    raise NoMatch
  end
end

#inspectObject



75
76
77
# File 'lib/command-set/result-list.rb', line 75

def inspect
  "<i(#{@order}) #{value.inspect}>"
end

#match(key) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/command-set/result-list.rb', line 57

def match(key)
  if key == :*
    return true
  elsif key == :**
    return true
  else
    match_on(key)
  end
end

#match_on(value) ⇒ Object



53
54
55
# File 'lib/command-set/result-list.rb', line 53

def match_on(value)
  return value.to_s == self.to_s
end

#next_siblingObject



48
49
50
51
# File 'lib/command-set/result-list.rb', line 48

def next_sibling
  return nil if self.parent.nil?
  return self.parent.after(self)
end

#to_sObject



40
41
42
# File 'lib/command-set/result-list.rb', line 40

def to_s
  return @value.to_s
end

#tree_order_nextObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/command-set/result-list.rb', line 27

def tree_order_next
  right = self.next_sibling
  if right.nil?
    if self.parent.nil?
      return nil
    else
      return self.parent.list_end
    end
  else
    return right
  end
end