Class: Stream::IntervalStream

Inherits:
BasicStream show all
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

Instance Method Summary collapse

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

#create_stream

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.


183
184
185
186
# File 'lib/stream.rb', line 183

def initialize (stop=0)
  @stop = stop - 1
  set_to_begin
end

Instance Attribute Details

#posObject (readonly)

Returns the value of attribute pos


179
180
181
# File 'lib/stream.rb', line 179

def pos
  @pos
end

Instance Method Details

#at_beginning?Boolean

Returns:

  • (Boolean)

188
# File 'lib/stream.rb', line 188

def at_beginning?; @pos < 0; end

#at_end?Boolean

Returns:

  • (Boolean)

189
# File 'lib/stream.rb', line 189

def at_end?; @pos == @stop; end

#basic_backwardObject


198
# File 'lib/stream.rb', line 198

def basic_backward;  @pos -= 1; @pos + 1; end

#basic_forwardObject


197
# File 'lib/stream.rb', line 197

def basic_forward; @pos += 1; end

#increment_stop(incr = 1) ⇒ Object

Increment the upper bound by incr.


195
# File 'lib/stream.rb', line 195

def increment_stop (incr=1); @stop += incr; end

#set_to_beginObject


192
# File 'lib/stream.rb', line 192

def set_to_begin; @pos = -1; end

#set_to_endObject


191
# File 'lib/stream.rb', line 191

def set_to_end; @pos = @stop; end