Class: MatchReduce::Index
- Inherits:
-
Object
- Object
- MatchReduce::Index
- Extended by:
- Forwardable
- Defined in:
- lib/match_reduce/index.rb
Overview
The Index holds all the aggregators, the reverse lookup data structure, and the ability to retrieve aggregators based on a pattern
Instance Attribute Summary collapse
-
#aggregators ⇒ Object
readonly
Returns the value of attribute aggregators.
-
#any ⇒ Object
readonly
Returns the value of attribute any.
-
#lookup ⇒ Object
readonly
Returns the value of attribute lookup.
Instance Method Summary collapse
- #find(pattern) ⇒ Object
-
#initialize(aggregators = [], any: ANY) ⇒ Index
constructor
A new instance of Index.
Constructor Details
#initialize(aggregators = [], any: ANY) ⇒ Index
Returns a new instance of Index.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/match_reduce/index.rb', line 22 def initialize(aggregators = [], any: ANY) @any = any @aggregators = Aggregator.array(aggregators).uniq(&:name) @lookup = {} all_keys = @aggregators.flat_map(&:keys) @record = HashMath::Record.new(all_keys, any) @aggregators.map do |aggregator| aggregator.patterns.each do |pattern| normalized_pattern = record.make!(pattern) get(normalized_pattern) << aggregator end end freeze end |
Instance Attribute Details
#aggregators ⇒ Object (readonly)
Returns the value of attribute aggregators.
16 17 18 |
# File 'lib/match_reduce/index.rb', line 16 def aggregators @aggregators end |
#any ⇒ Object (readonly)
Returns the value of attribute any.
16 17 18 |
# File 'lib/match_reduce/index.rb', line 16 def any @any end |
#lookup ⇒ Object (readonly)
Returns the value of attribute lookup.
16 17 18 |
# File 'lib/match_reduce/index.rb', line 16 def lookup @lookup end |
Instance Method Details
#find(pattern) ⇒ Object
41 42 43 |
# File 'lib/match_reduce/index.rb', line 41 def find(pattern) lookup.fetch(pattern, []) end |