Class: AudienceMatcher

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

Defined Under Namespace

Classes: Result

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(deserializer) ⇒ AudienceMatcher

Returns a new instance of AudienceMatcher.



9
10
11
12
# File 'lib/audience_matcher.rb', line 9

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

Instance Attribute Details

#deserializerObject

Returns the value of attribute deserializer.



7
8
9
# File 'lib/audience_matcher.rb', line 7

def deserializer
  @deserializer
end

#json_exprObject

Returns the value of attribute json_expr.



7
8
9
# File 'lib/audience_matcher.rb', line 7

def json_expr
  @json_expr
end

Instance Method Details

#evaluate(audience, attributes) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/audience_matcher.rb', line 26

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