Class: AudienceMatcher
- Inherits:
-
Object
- Object
- AudienceMatcher
- Defined in:
- lib/audience_matcher.rb
Defined Under Namespace
Classes: Result
Instance Attribute Summary collapse
-
#deserializer ⇒ Object
Returns the value of attribute deserializer.
-
#json_expr ⇒ Object
Returns the value of attribute json_expr.
Instance Method Summary collapse
- #evaluate(audience, attributes) ⇒ Object
-
#initialize(deserializer) ⇒ AudienceMatcher
constructor
A new instance of AudienceMatcher.
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
#deserializer ⇒ Object
Returns the value of attribute deserializer.
7 8 9 |
# File 'lib/audience_matcher.rb', line 7 def deserializer @deserializer end |
#json_expr ⇒ Object
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 |