Class: Factbase::IndexedLt

Inherits:
Object
  • Object
show all
Defined in:
lib/factbase/indexed/indexed_lt.rb

Overview

Indexed term ‘lt’.

Instance Method Summary collapse

Constructor Details

#initialize(term, idx) ⇒ IndexedLt

Returns a new instance of IndexedLt.



8
9
10
11
# File 'lib/factbase/indexed/indexed_lt.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
# File 'lib/factbase/indexed/indexed_lt.rb', line 13

def predict(maps, _fb, params)
  op1, op2 = @term.operands
  return unless op1.is_a?(Symbol) && _scalar?(op2)
  prop = op1.to_s
  target = op2.is_a?(Symbol) ? params[op2.to_s]&.first : op2
  return maps || [] if target.nil?
  key = [maps.object_id, prop, :facts]
  @idx[key] ||= { facts: [], count: 0 }
  entry = @idx[key]
  _feed(maps.to_a, entry, prop)
  matched = _search(entry, target)
  maps.respond_to?(:repack) ? maps.repack(matched) : matched
end