Class: Wukong::Processor::Improver
- Inherits:
-
Wukong::Processor
- Object
- Hanuman::Stage
- Wukong::Processor
- Wukong::Processor::Improver
- Defined in:
- lib/wukong/widget/reducers/improver.rb
Overview
A base widget for building more complex improver widgets.
Constant Summary
Constants inherited from Wukong::Processor
Instance Attribute Summary collapse
-
#group ⇒ Object
The current group of records.
Attributes included from Hanuman::StageInstanceMethods
Instance Method Summary collapse
-
#accumulate(record) ⇒ Object
Accumulates another +record+.
-
#get_function(record) ⇒ Object
All kinds of assumptions here, record is tab-delimited and the first field is a name of a function to call.
-
#improve(prev, group) ⇒ Object
Improve prev with group.
-
#process(record) ⇒ Object
Processes the
record
. - #recordize(record) ⇒ Object
-
#setup ⇒ Object
Sets up this improver by defining an initial key (with a value that is unlikely to be found in real data) and calling
#zero
with no record. -
#zero ⇒ Object
Starts accumulation for a new key.
Methods inherited from Wukong::Processor
configure, description, #finalize, #perform_action, #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
#group ⇒ Object
The current group of records.
8 9 10 |
# File 'lib/wukong/widget/reducers/improver.rb', line 8 def group @group end |
Instance Method Details
#accumulate(record) ⇒ Object
Accumulates another +record+.
59 60 61 |
# File 'lib/wukong/widget/reducers/improver.rb', line 59 def accumulate record self.group << record end |
#get_function(record) ⇒ Object
All kinds of assumptions here, record is tab-delimited and the first field is a name of a function to call
28 29 30 |
# File 'lib/wukong/widget/reducers/improver.rb', line 28 def get_function record record.first end |
#improve(prev, group) ⇒ Object
Improve prev with group
66 67 |
# File 'lib/wukong/widget/reducers/improver.rb', line 66 def improve prev, group end |
#process(record) ⇒ Object
Processes the record
.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/wukong/widget/reducers/improver.rb', line 33 def process(record) fields = recordize(record) func = get_function(fields) case func when 'zero' then yield zero when 'accumulate' then accumulate(fields[1..-1]) when 'improve' then yield improve(fields[1], self.group) self.group = [] else raise NoMethodError, "undefined method #{func} for Improver" end STDOUT.flush # WHY? Because. end |
#recordize(record) ⇒ Object
18 19 20 |
# File 'lib/wukong/widget/reducers/improver.rb', line 18 def recordize record record.split("\t") end |
#setup ⇒ Object
Sets up this improver by defining an initial key (with a
value that is unlikely to be found in real data) and calling
#zero
with no record.
13 14 15 16 |
# File 'lib/wukong/widget/reducers/improver.rb', line 13 def setup @key = :__first_group__ zero end |
#zero ⇒ Object
Starts accumulation for a new key. Return what you would with no improvements.
52 53 54 |
# File 'lib/wukong/widget/reducers/improver.rb', line 52 def zero self.group = [] end |