Class: Stages::Unique

Inherits:
Stage
  • Object
show all
Defined in:
lib/stages/unique.rb

Instance Attribute Summary

Attributes inherited from Stage

#source

Instance Method Summary collapse

Methods inherited from Stage

#die, #done?, #drop_leftmost!, #each, #end?, #handle_value, #initialize_loop, #input, #length, #output, #reset, #root_source, #run, #source_empty?, #to_enum, #|

Constructor Details

#initialize(options = { }) ⇒ Unique

Returns a new instance of Unique.



5
6
7
8
# File 'lib/stages/unique.rb', line 5

def initialize(options = { })
  @prefetch = options[:prefetch]
  super()
end

Instance Method Details

#processObject



10
11
12
13
14
15
16
17
18
19
# File 'lib/stages/unique.rb', line 10

def process
  set = Set.new
  while !source_empty?
    i = input
    added = set.add? i
    handle_value i if added && !@prefetch
  end
  set.each{ |x| handle_value x} if @prefetch
  set = nil
end