Class: Collector

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(procs, fin) ⇒ Collector

Returns a new instance of Collector.



5
6
7
8
9
10
# File 'lib/collector.rb', line 5

def initialize(procs, fin)
  @procs    = procs
  @finalize = fin
  @counter  = 0
  @collect  = nil
end

Instance Attribute Details

#collectObject

Returns the value of attribute collect.



3
4
5
# File 'lib/collector.rb', line 3

def collect
  @collect
end

Instance Method Details

#add(f) ⇒ Object



12
13
14
# File 'lib/collector.rb', line 12

def add(f)
  @procs.push(f)
end

#proc_finishedObject



22
23
24
25
26
27
# File 'lib/collector.rb', line 22

def proc_finished
  @counter += 1
  if @procs.size == @counter
    @finalize.call(self)
  end
end

#startObject



16
17
18
19
20
# File 'lib/collector.rb', line 16

def start
  @procs.each do |f|
    f.call(self)
  end
end