Class: PiecePipe::HashedAggregator

Inherits:
PipelineElement show all
Defined in:
lib/piece_pipe/hashed_aggregator.rb

Instance Attribute Summary

Attributes inherited from PipelineElement

#source

Instance Method Summary collapse

Methods inherited from PipelineElement

#to_enum

Constructor Details

#initializeHashedAggregator

Returns a new instance of HashedAggregator.



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

def initialize
  @hash = {}
end

Instance Method Details

#aggregate(key, values) ⇒ Object



22
23
24
# File 'lib/piece_pipe/hashed_aggregator.rb', line 22

def aggregate(key, values)
  produce key: key, values: values 
end

#generate_sequenceObject



7
8
9
10
11
12
# File 'lib/piece_pipe/hashed_aggregator.rb', line 7

def generate_sequence
  super
  @hash.each do |key,values|
    aggregate key, values
  end
end

#process(item) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/piece_pipe/hashed_aggregator.rb', line 14

def process(item)
  raise "HashedAggregator requires inputs to be Hashes with :key and :value" unless item.keys.include?(:key) and item.keys.include?(:value)
  # TODO : check key/val keys in item
  #
  @hash[item[:key]] ||= []
  @hash[item[:key]] << item[:value]
end