Class: Overule::Operator

Inherits:
Object
  • Object
show all
Defined in:
lib/overule/operator.rb

Overview

Provides comparison operations for rule evaluation Supports various operators like equality, inequality, greater/less than, inclusion, and range checking

Constant Summary collapse

OPERATORS =
{
  "eq" => ->(a, b) { a == b },
  "neq" => ->(a, b) { a != b },
  "gt" => ->(a, b) { a > b },
  "lt" => ->(a, b) { a < b },
  "gte" => ->(a, b) { a >= b },
  "lte" => ->(a, b) { a <= b },
  "in" => ->(a, b) { b.include?(a) },
  "nin" => ->(a, b) { !b.include?(a) },
  "contains" => ->(a, b) { a.include?(b) },
  "range" => ->(a, b) { a >= b.first && a <= b.last }
}.freeze

Class Method Summary collapse

Class Method Details

.operate(operator, actual, expected) ⇒ Object

Raises:

  • (NoMethodError)


19
20
21
22
23
# File 'lib/overule/operator.rb', line 19

def self.operate(operator, actual, expected)
  raise NoMethodError, "Unsupported operator: #{operator}" unless OPERATORS.key?(operator)

  OPERATORS[operator].call(actual, expected)
end