Sha256: 0914bd8ce07106a4ea907b9231f12a73be3fa3e969add6b14b1c631d3ef9e9b8

Contents?: true

Size: 730 Bytes

Versions: 8

Compression:

Stored size: 730 Bytes

Contents

# frozen_string_literal: true

require "json"
require_relative "json_expr/json_expr"

class AudienceMatcher
  attr_accessor :deserializer, :json_expr

  def initialize(deserializer)
    @deserializer = deserializer
    @json_expr = JsonExpr.new
  end

  class Result
    attr_accessor :result

    def initialize(result)
      @result = result
    end

    def get
      @result
    end
  end

  def evaluate(audience, attributes)
    audience_map = JSON.parse(audience, symbolize_names: true)

    unless audience_map.nil?
      filter = audience_map[:filter]
      if filter.is_a?(Hash) || filter.is_a?(Array)
        Result.new(@json_expr.evaluate_boolean_expr(filter, attributes))
      end
    end
  rescue
    nil
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
absmartly-sdk-1.1.2 lib/audience_matcher.rb
absmartly-sdk-1.1.1 lib/audience_matcher.rb
absmartly-sdk-1.1.0 lib/audience_matcher.rb
absmartly-sdk-1.0.8 lib/audience_matcher.rb
absmartly-sdk-1.0.7 lib/audience_matcher.rb
absmartly-sdk-1.0.6 lib/audience_matcher.rb
absmartly-sdk-1.0.5 lib/audience_matcher.rb
absmartly-sdk-0.1.2 lib/audience_matcher.rb