Class: MatchReduce::Processor
- Inherits:
-
Object
- Object
- MatchReduce::Processor
- Extended by:
- Forwardable
- Defined in:
- lib/match_reduce/processor.rb,
lib/match_reduce/processor/result.rb,
lib/match_reduce/processor/result_builder.rb,
lib/match_reduce/processor/results_builder.rb
Overview
This is the main lifecycle of the algorithm. You initialize a new instance of this class using aggregators, then you pump in records into it. Once done, call #results to get the results.
Defined Under Namespace
Classes: Result, ResultBuilder, ResultsBuilder
Instance Method Summary collapse
- #add(record) ⇒ Object
- #add_each(records) ⇒ Object
-
#initialize(aggregators, resolver: Objectable.resolver, any: ANY) ⇒ Processor
constructor
A new instance of Processor.
Constructor Details
#initialize(aggregators, resolver: Objectable.resolver, any: ANY) ⇒ Processor
Returns a new instance of Processor.
23 24 25 26 27 28 |
# File 'lib/match_reduce/processor.rb', line 23 def initialize(aggregators, resolver: Objectable.resolver, any: ANY) @index = Index.new(aggregators, any: any) @results_builder = ResultsBuilder.new(index.aggregators, resolver) freeze end |
Instance Method Details
#add(record) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/match_reduce/processor.rb', line 34 def add(record) hit_aggregators = Set.new record_patterns(record).each do |hash_pattern| # Each index find hit means the aggregator matched on the record index.find(hash_pattern).each do |aggregator| next if hit_aggregators.include?(aggregator) add_to_results_builder(aggregator, record) hit_aggregators << aggregator end end self end |
#add_each(records) ⇒ Object
30 31 32 |
# File 'lib/match_reduce/processor.rb', line 30 def add_each(records) tap { records.each { |record| add(record) } } end |