Class: Wukong::Processor::Count
- Inherits:
-
Accumulator
- Object
- Hanuman::Stage
- Wukong::Processor
- Accumulator
- Wukong::Processor::Count
- Defined in:
- lib/wukong/widget/reducers/count.rb
Overview
A processor which counts the total number of its input records.
On it's own, this widget is really just a poor man's wc -l
.
It's really intended to serve as a superclass for more complex
accumulators.
Direct Known Subclasses
Constant Summary
Constants inherited from Wukong::Processor
Instance Attribute Summary collapse
-
#size ⇒ Object
The total size of the input recors.
Attributes inherited from Accumulator
Attributes included from Hanuman::StageInstanceMethods
Instance Method Summary collapse
-
#accumulate(record) ⇒ Object
Accumulate a
record
by incrmenting the total size. -
#finalize {|size| ... } ⇒ Object
Yields the total size.
-
#get_key(record) ⇒ :__first__group__
Keeps all records in the same group so that one count is emitted at the end.
-
#setup ⇒ Object
Initializes the count to 0.
Methods inherited from Accumulator
Methods inherited from Wukong::Processor
configure, description, #perform_action, #process, #receive_action, #stop
Methods included from Logging
Methods inherited from Hanuman::Stage
Methods included from Hanuman::StageClassMethods
#builder, #label, #register, #set_builder
Methods included from Hanuman::StageInstanceMethods
#add_link, #linkable_name, #root
Instance Attribute Details
#size ⇒ Object
The total size of the input recors.
33 34 35 |
# File 'lib/wukong/widget/reducers/count.rb', line 33 def size @size end |
Instance Method Details
#accumulate(record) ⇒ Object
Accumulate a record
by incrmenting the total size.
44 45 46 |
# File 'lib/wukong/widget/reducers/count.rb', line 44 def accumulate record self.size += 1 end |
#finalize {|size| ... } ⇒ Object
Yields the total size.
66 67 68 |
# File 'lib/wukong/widget/reducers/count.rb', line 66 def finalize yield self.size end |
#get_key(record) ⇒ :__first__group__
Keeps all records in the same group so that one count is emitted at the end.
Overriding this method and returning different keys for different records is the beginning of constructing a "group by" type widget.
58 59 60 |
# File 'lib/wukong/widget/reducers/count.rb', line 58 def get_key record :__first_group__ end |
#setup ⇒ Object
Initializes the count to 0.
36 37 38 39 |
# File 'lib/wukong/widget/reducers/count.rb', line 36 def setup super() @size = 0 end |