Class: Factbase::IndexedEq
- Inherits:
-
Object
- Object
- Factbase::IndexedEq
- Defined in:
- lib/factbase/indexed/indexed_eq.rb
Overview
Indexed term ‘eq’.
Instance Method Summary collapse
-
#initialize(term, idx) ⇒ IndexedEq
constructor
A new instance of IndexedEq.
- #predict(maps, _fb, params) ⇒ Object
Constructor Details
#initialize(term, idx) ⇒ IndexedEq
Returns a new instance of IndexedEq.
8 9 10 11 |
# File 'lib/factbase/indexed/indexed_eq.rb', line 8 def initialize(term, idx) @term = term @idx = idx end |
Instance Method Details
#predict(maps, _fb, params) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/factbase/indexed/indexed_eq.rb', line 13 def predict(maps, _fb, params) first_operand = @term.operands[0] second_operand = @term.operands[1] return unless first_operand.is_a?(Symbol) && _scalar?(second_operand) first_operand = first_operand.to_s key = [maps.object_id, first_operand, @term.op] @idx[key] ||= { facts: {}, count: 0 } entry = @idx[key] _feed(maps.to_a, entry, first_operand) keys = _resolve(second_operand, params) matches = keys.flat_map { |k| entry[:facts][k] || [] } matches = matches.uniq(&:object_id) if keys.size > 1 maps.respond_to?(:repack) ? maps.repack(matches) : matches end |