Class: SknUtils::Lists::LinkNode
- Inherits:
-
Object
- Object
- SknUtils::Lists::LinkNode
- Defined in:
- lib/skn_utils/lists/link_node.rb
Instance Attribute Summary collapse
-
#next ⇒ Object
Returns the value of attribute next.
-
#prev ⇒ Object
Returns the value of attribute prev.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(val, anchor_node = nil, strategy = :after) ⇒ LinkNode
constructor
A new instance of LinkNode.
- #match_by_value(other_value) ⇒ Object
-
#remove! ⇒ Object
returns next node.
- #to_s ⇒ Object
Constructor Details
#initialize(val, anchor_node = nil, strategy = :after) ⇒ LinkNode
Returns a new instance of LinkNode.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/skn_utils/lists/link_node.rb', line 11 def initialize(val, anchor_node=nil, strategy=:after) @value = val @prev = nil @next = nil case strategy when :single # after logic anchor_node.next = self if anchor_node when :before @prev = anchor_node.prev if anchor_node @next = anchor_node anchor_node.prev = self if anchor_node when :after @prev = anchor_node @next = anchor_node.next if anchor_node anchor_node.next = self if anchor_node @next.prev = self if @next when :circle_before @prev = anchor_node ? anchor_node.prev : self @next = anchor_node ? anchor_node : self anchor_node.prev = self if anchor_node @prev.next = self if anchor_node when :circle_after @prev = anchor_node ? anchor_node : self @next = anchor_node ? anchor_node.next : self anchor_node.next = self if anchor_node @next.prev = self if anchor_node end end |
Instance Attribute Details
#next ⇒ Object
Returns the value of attribute next.
9 10 11 |
# File 'lib/skn_utils/lists/link_node.rb', line 9 def next @next end |
#prev ⇒ Object
Returns the value of attribute prev.
9 10 11 |
# File 'lib/skn_utils/lists/link_node.rb', line 9 def prev @prev end |
#value ⇒ Object
Returns the value of attribute value.
9 10 11 |
# File 'lib/skn_utils/lists/link_node.rb', line 9 def value @value end |
Instance Method Details
#match_by_value(other_value) ⇒ Object
41 42 43 |
# File 'lib/skn_utils/lists/link_node.rb', line 41 def match_by_value(other_value) self.value === other_value end |
#remove! ⇒ Object
returns next node
46 47 48 49 50 51 52 |
# File 'lib/skn_utils/lists/link_node.rb', line 46 def remove! next_node = @next @value = nil @prev = nil @next = nil next_node end |
#to_s ⇒ Object
54 55 56 |
# File 'lib/skn_utils/lists/link_node.rb', line 54 def to_s "Node with value: #{@value}" end |