Class: Stages::Count
Instance Attribute Summary
Attributes inherited from Stage
Instance Method Summary collapse
Methods inherited from Stage
#die, #done?, #drop_leftmost!, #each, #end?, #handle_value, #initialize, #initialize_loop, #input, #length, #output, #reset, #root_source, #run, #source_empty?, #to_enum, #|
Constructor Details
This class inherits a constructor from Stages::Stage
Instance Method Details
#process ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/stages/count.rb', line 3 def process result = Hash.new{ |h, k| h[k] = 0 } while !source_empty? v = source.run if v.is_a? Hash v.each_pair{ |key, value| result[key] += (value || 0) } else result[v] += 1 end end handle_value result end |