Class: Frill::List::Node
- Inherits:
-
Object
- Object
- Frill::List::Node
- Defined in:
- lib/frill/frill.rb
Instance Attribute Summary collapse
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#next ⇒ Object
Returns the value of attribute next.
-
#previous ⇒ Object
Returns the value of attribute previous.
Instance Method Summary collapse
- #first ⇒ Object
-
#initialize(label) ⇒ Node
constructor
A new instance of Node.
- #last ⇒ Object
- #move_after(node) ⇒ Object
- #move_before(node) ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(label) ⇒ Node
Returns a new instance of Node.
122 123 124 125 126 |
# File 'lib/frill/frill.rb', line 122 def initialize(label) @label = label @next = nil @previous = nil end |
Instance Attribute Details
#label ⇒ Object (readonly)
Returns the value of attribute label.
120 121 122 |
# File 'lib/frill/frill.rb', line 120 def label @label end |
#next ⇒ Object
Returns the value of attribute next.
119 120 121 |
# File 'lib/frill/frill.rb', line 119 def next @next end |
#previous ⇒ Object
Returns the value of attribute previous.
119 120 121 |
# File 'lib/frill/frill.rb', line 119 def previous @previous end |
Instance Method Details
#first ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/frill/frill.rb', line 144 def first node = nil current_node = self until node if current_node.previous current_node = current_node.previous else node = current_node end end node end |
#last ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/frill/frill.rb', line 159 def last current_node = self last_node = nil until last_node if current_node.next current_node = current_node.next else last_node = current_node end end last_node end |
#move_after(node) ⇒ Object
136 137 138 139 140 141 142 |
# File 'lib/frill/frill.rb', line 136 def move_after node previous_node = node.last first_node = first previous_node.next = first_node first_node.previous = previous_node end |
#move_before(node) ⇒ Object
128 129 130 131 132 133 134 |
# File 'lib/frill/frill.rb', line 128 def move_before node next_node = node.first previous_node = self.last previous_node.next = next_node next_node.previous = previous_node end |
#to_a ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/frill/frill.rb', line 174 def to_a current_node = self list = [] until current_node == nil list << current_node.label current_node = current_node.next end list end |