Sha256: 96e6a9264555384d241d72abde1bd0120c586696b4b0c1c84be88539e0ac2a35

Contents?: true

Size: 968 Bytes

Versions: 2

Compression:

Stored size: 968 Bytes

Contents

# frozen_string_literal: true

require_relative "./expr_evaluator"
Dir["lib/json_expr/operators/*.rb"].each { |file| require "./#{file}" }

class JsonExpr
  attr_accessor :operators
  attr_accessor :vars

  def initialize
    @operators = {
      "and": AndCombinator.new,
      "or": OrCombinator.new,
      "value": ValueOperator.new,
      "var": VarOperator.new,
      "null": NilOperator.new,
      "not": NotOperator.new,
      "in": InOperator.new,
      "match": MatchOperator.new,
      "eq": EqualsOperator.new,
      "gt": GreaterThanOperator.new,
      "gte": GreaterThanOrEqualOperator.new,
      "lt": LessThanOperator.new,
      "lte": LessThanOrEqualOperator.new
    }
  end

  def evaluate_boolean_expr(expr, vars)
    evaluator = ExprEvaluator.new(operators, vars)
    evaluator.boolean_convert(evaluator.evaluate(expr))
  end

  def evaluate_expr(expr, vars)
    evaluator = ExprEvaluator.new(operators, vars)
    evaluator.evaluate(expr)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
absmartly-sdk-1.0.5 lib/json_expr/json_expr.rb
absmartly-sdk-0.1.2 lib/json_expr/json_expr.rb