Class: PiecePipe::HashedAggregator
- Inherits:
-
PipelineElement
- Object
- PipelineElement
- PiecePipe::HashedAggregator
- Defined in:
- lib/piece_pipe/hashed_aggregator.rb
Instance Attribute Summary
Attributes inherited from PipelineElement
Instance Method Summary collapse
- #aggregate(key, values) ⇒ Object
- #generate_sequence ⇒ Object
-
#initialize ⇒ HashedAggregator
constructor
A new instance of HashedAggregator.
- #process(item) ⇒ Object
Methods inherited from PipelineElement
Constructor Details
#initialize ⇒ HashedAggregator
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_sequence ⇒ Object
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 |