Class: Stream::IntervalStream
- Inherits:
-
BasicStream
- Object
- BasicStream
- Stream::IntervalStream
- Defined in:
- lib/stream.rb
Overview
A simple Iterator for iterating over a sequence of integers starting from zero up to a given upper bound. Mainly used by Stream::FilteredStream. Could be made private but if somebody needs it here it is. Is there a better name for it?
The upper bound is stored in the instance variable @stop which can be incremented dynamically by the method increment_stop.
Instance Attribute Summary collapse
-
#pos ⇒ Object
readonly
Returns the value of attribute pos.
Instance Method Summary collapse
- #at_beginning? ⇒ Boolean
- #at_end? ⇒ Boolean
- #basic_backward ⇒ Object
- #basic_forward ⇒ Object
-
#increment_stop(incr = 1) ⇒ Object
Increment the upper bound by incr.
-
#initialize(stop = 0) ⇒ IntervalStream
constructor
Create a new IntervalStream with upper bound stop.
- #set_to_begin ⇒ Object
- #set_to_end ⇒ Object
Methods included from Stream
#+, #backward, #collect, #concatenate, #concatenate_collected, #create_stream, #current, #current_edge, #each, #empty?, #filtered, #first, #forward, #last, #modify, #move_backward_until, #move_forward_until, #peek, #remove_first, #remove_last, #reverse, #unwrapped
Methods included from Enumerable
Constructor Details
#initialize(stop = 0) ⇒ IntervalStream
Create a new IntervalStream with upper bound stop. stop - 1 is the last element. By default stop is zero which means that the stream is empty.
255 256 257 258 |
# File 'lib/stream.rb', line 255 def initialize(stop = 0) @stop = stop - 1 set_to_begin end |
Instance Attribute Details
#pos ⇒ Object (readonly)
Returns the value of attribute pos.
251 252 253 |
# File 'lib/stream.rb', line 251 def pos @pos end |
Instance Method Details
#at_beginning? ⇒ Boolean
260 261 262 |
# File 'lib/stream.rb', line 260 def at_beginning? @pos < 0 end |
#at_end? ⇒ Boolean
264 265 266 |
# File 'lib/stream.rb', line 264 def at_end? @pos == @stop end |
#basic_backward ⇒ Object
285 286 287 288 |
# File 'lib/stream.rb', line 285 def basic_backward @pos -= 1 @pos + 1 end |
#basic_forward ⇒ Object
281 282 283 |
# File 'lib/stream.rb', line 281 def basic_forward @pos += 1 end |
#increment_stop(incr = 1) ⇒ Object
Increment the upper bound by incr.
277 278 279 |
# File 'lib/stream.rb', line 277 def increment_stop(incr = 1) @stop += incr end |
#set_to_begin ⇒ Object
272 273 274 |
# File 'lib/stream.rb', line 272 def set_to_begin @pos = -1 end |
#set_to_end ⇒ Object
268 269 270 |
# File 'lib/stream.rb', line 268 def set_to_end @pos = @stop end |