Class: Factbase::Compare
- Defined in:
- lib/factbase/terms/compare.rb
Overview
Compares two values using a specified operation.
Instance Method Summary collapse
-
#evaluate(fact, maps, fb) ⇒ Boolean
Evaluate term on a fact.
-
#initialize(operation, operands) ⇒ Compare
constructor
Constructor.
Methods included from TermShared
Constructor Details
#initialize(operation, operands) ⇒ Compare
Constructor.
13 14 15 16 17 |
# File 'lib/factbase/terms/compare.rb', line 13 def initialize(operation, operands) super() @op = operation @operands = operands end |
Instance Method Details
#evaluate(fact, maps, fb) ⇒ Boolean
Evaluate term on a fact.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/factbase/terms/compare.rb', line 24 def evaluate(fact, maps, fb) assert_args(2) lefts = _values(0, fact, maps, fb) return false if lefts.nil? rights = _values(1, fact, maps, fb) return false if rights.nil? lefts.any? do |l| l = l.floor if l.is_a?(Time) && @op == :== rights.any? do |r| r = r.floor if r.is_a?(Time) && @op == :== l.send(@op, r) end end end |