Module: LogicHelper
- Included in:
- RuleEvaluator
- Defined in:
- lib/rast/rules/logic_helper.rb
Overview
Provides logic evaluation functionalities.
Constant Summary collapse
- TRUE =
/**
* Custom logical AND/OR evaluator. * * @author Royce */
'*true'
- FALSE =
'*false'
- OPPOSITE =
{ TRUE => FALSE, FALSE => TRUE }.freeze
- LOGIC_PRIMARY_RESULT =
{ and: FALSE, or: TRUE }.freeze
Instance Method Summary collapse
-
#close_bracket?(token: '') ⇒ Boolean
/** * Check if the token is closing bracket.
-
#open_bracket?(token: '') ⇒ Boolean
/** * Check if the token is opening bracket.
-
#perform_logical(scenario: [], left: {}, right: {}, operation: :nil) ⇒ Object
/** * @scenario list of scenario tokens.
Instance Method Details
#close_bracket?(token: '') ⇒ Boolean
/**
* Check if the token is closing bracket.
*
* @param token Input <code>String</code> token
* @return <code>boolean</code> output
*/
59 60 61 |
# File 'lib/rast/rules/logic_helper.rb', line 59 def close_bracket?(token: '') token == ')' end |
#open_bracket?(token: '') ⇒ Boolean
/**
* Check if the token is opening bracket.
*
* @token Input <code>String</code> token
* @return <code>boolean</code> output
*/
49 50 51 |
# File 'lib/rast/rules/logic_helper.rb', line 49 def open_bracket?(token: '') token == '(' end |
#perform_logical(scenario: [], left: {}, right: {}, operation: :nil) ⇒ Object
/**
* @scenario list of scenario tokens.
* @left left left token object.
* @right right right token object.
* @operation :and or :or.
* @returns String boolean value, can be internal, thus it is string.
*/
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rast/rules/logic_helper.rb', line 31 def perform_logical(scenario: [], left: {}, right: {}, operation: :nil) evaluated = both_internal?(left, right, operation) return evaluated if evaluated default = operation == :and ? TRUE : FALSE return present?(scenario, right).to_s if internal_match?(default, left) return present?(scenario, left).to_s if internal_match?(default, right) send("evaluate_#{operation}", scenario, left, right).to_s end |