Class: Wukong::Processor::Uniq
- Inherits:
-
Accumulator
- Object
- Hanuman::Stage
- Wukong::Processor
- Accumulator
- Wukong::Processor::Uniq
- Defined in:
- lib/wukong/widget/reducers/uniq.rb
Overview
A processor which emits only unique records from its input.
It's intended to work just like uniq.
Constant Summary
Constants inherited from Wukong::Processor
Instance Attribute Summary collapse
-
#size ⇒ Object
The total size of the input recors.
Attributes inherited from Accumulator
Instance Method Summary collapse
-
#accumulate(record) ⇒ Object
Accumulate a
recordby incrmenting the total size. -
#finalize {|size| ... } ⇒ Object
Yields the total size.
-
#setup ⇒ Object
Initializes the count to 0.
Methods inherited from Accumulator
Methods inherited from Wukong::Processor
configure, consumes, description, #expected_record_type, #expected_serialization, #perform_action, #process, produces, #receive_action, #stop, valid_serializer?, validate_and_set_serialization
Methods included from Logging
Methods included from Hanuman::StageClassMethods
#builder, #label, #register, #set_builder
Instance Attribute Details
#size ⇒ Object
The total size of the input recors.
60 61 62 |
# File 'lib/wukong/widget/reducers/uniq.rb', line 60 def size @size end |
Instance Method Details
#accumulate(record) ⇒ Object
Accumulate a record by incrmenting the total size.
71 72 73 |
# File 'lib/wukong/widget/reducers/uniq.rb', line 71 def accumulate record self.size += 1 end |
#finalize {|size| ... } ⇒ Object
Yields the total size.
79 80 81 82 83 84 85 |
# File 'lib/wukong/widget/reducers/uniq.rb', line 79 def finalize if count yield [key, self.size] else yield key end end |
#setup ⇒ Object
Initializes the count to 0.
63 64 65 66 |
# File 'lib/wukong/widget/reducers/uniq.rb', line 63 def setup super() @size = 0 end |