* Takes the fact result and compares it to the condition 'value', using the operator * LHS OPER RHS * * * @param {Almanac} almanac * @param {Map} operatorMap - map of available operators, keyed by operator na
(almanac, operatorMap)
| 88 | * @returns {Boolean} - evaluation result |
| 89 | */ |
| 90 | evaluate (almanac, operatorMap) { |
| 91 | if (!almanac) return Promise.reject(new Error('almanac required')) |
| 92 | if (!operatorMap) return Promise.reject(new Error('operatorMap required')) |
| 93 | if (this.isBooleanOperator()) { return Promise.reject(new Error('Cannot evaluate() a boolean condition')) } |
| 94 | |
| 95 | const op = operatorMap.get(this.operator) |
| 96 | if (!op) { return Promise.reject(new Error(`Unknown operator: ${this.operator}`)) } |
| 97 | |
| 98 | return Promise.all([ |
| 99 | almanac.getValue(this.value), |
| 100 | almanac.factValue(this.fact, this.params, this.path) |
| 101 | ]).then(([rightHandSideValue, leftHandSideValue]) => { |
| 102 | const result = op.evaluate(leftHandSideValue, rightHandSideValue) |
| 103 | debug( |
| 104 | `condition::evaluate <${JSON.stringify(leftHandSideValue)} ${ |
| 105 | this.operator |
| 106 | } ${JSON.stringify(rightHandSideValue)}?> (${result})` |
| 107 | ) |
| 108 | return { |
| 109 | result, |
| 110 | leftHandSideValue, |
| 111 | rightHandSideValue, |
| 112 | operator: this.operator |
| 113 | } |
| 114 | }) |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Returns the boolean operator for the condition |
nothing calls this directly
no test coverage detected