Module: Optimizely::Audience
- Defined in:
- lib/optimizely/audience.rb
Class Method Summary collapse
Class Method Details
.user_in_experiment?(config, experiment, attributes) ⇒ Boolean
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/optimizely/audience.rb', line 25 def user_in_experiment?(config, experiment, attributes) # Determine for given experiment if user satisfies the audiences for the experiment. # # config - Representation of the Optimizely project config. # experiment - Experiment for which visitor is to be bucketed. # attributes - Hash representing user attributes which will be used in determining if # the audience conditions are met. # # Returns boolean representing if user satisfies audience conditions for any of the audiences or not. audience_ids = experiment['audienceIds'] # Return true if there are no audiences return true if audience_ids.empty? # Return false if there are audiences but no attributes return false unless attributes # Return true if any one of the audience conditions are met @condition_evaluator = ConditionEvaluator.new(attributes) audience_ids.each do |audience_id| audience = config.get_audience_from_id(audience_id) audience_conditions = audience['conditions'] audience_conditions = JSON.parse(audience_conditions) return true if @condition_evaluator.evaluate(audience_conditions) end false end |