Class: Rjq::Runtime::InputQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/rjq/runtime.rb

Constant Summary collapse

END_OF_INPUT =
Object.new.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(records) ⇒ InputQueue

Returns a new instance of InputQueue.



152
153
154
155
156
# File 'lib/rjq/runtime.rb', line 152

def initialize(records)
  @records = records.to_enum
  @next_record = nil
  @current_record = nil
end

Instance Attribute Details

#current_recordObject (readonly)

Returns the value of attribute current_record.



150
151
152
# File 'lib/rjq/runtime.rb', line 150

def current_record
  @current_record
end

Instance Method Details

#each_remainingObject



174
175
176
177
178
# File 'lib/rjq/runtime.rb', line 174

def each_remaining
  return enum_for(:each_remaining) unless block_given?

  yield shift until empty?
end

#empty?Boolean

Returns:

  • (Boolean)


158
159
160
# File 'lib/rjq/runtime.rb', line 158

def empty?
  peek.equal?(END_OF_INPUT)
end

#remaining_valuesObject



180
181
182
# File 'lib/rjq/runtime.rb', line 180

def remaining_values
  each_remaining.to_a
end

#shiftObject



170
171
172
# File 'lib/rjq/runtime.rb', line 170

def shift
  shift_record&.value
end

#shift_recordObject



162
163
164
165
166
167
168
# File 'lib/rjq/runtime.rb', line 162

def shift_record
  record = peek
  return if record.equal?(END_OF_INPUT)

  @next_record = nil
  @current_record = record
end