Class: Kameleoon::Targeting::TargetExperimentCondition Private

Inherits:
VisitorScopeCondition show all
Includes:
Exception
Defined in:
lib/kameleoon/targeting/conditions/target_experiment_condition.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

TargetExperiment represents an instance of Experiment condition in user account

Defined Under Namespace

Classes: TargetingData

Constant Summary

Constants inherited from VisitorScopeCondition

VisitorScopeCondition::MAX_VISITOR_VISIT_COUNT, VisitorScopeCondition::MIN_VISITOR_VISIT_COUNT

Instance Attribute Summary

Attributes inherited from Condition

#id, #include, #type

Instance Method Summary collapse

Constructor Details

#initialize(json_condition) ⇒ TargetExperimentCondition

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of TargetExperimentCondition.



13
14
15
16
17
18
19
# File 'lib/kameleoon/targeting/conditions/target_experiment_condition.rb', line 13

def initialize(json_condition)
  super(json_condition, VisitScope::CURRENT_VISIT)

  @variation_id = json_condition['variationId'] || -1
  @experiment_id = json_condition['experimentId'] || -1
  @variation_match_type = json_condition['variationMatchType'] || Operator::UNKNOWN
end

Instance Method Details

#check(data) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/kameleoon/targeting/conditions/target_experiment_condition.rb', line 21

def check(data)
  return false unless data.is_a?(TargetingData)

  variation = data.variations&.get(@experiment_id)
  variation = nil if !variation.nil? && variation.assignment_time < assignment_threshold(data.visitor_visits)
  case @variation_match_type
  when Operator::ANY
    return !variation.nil?
  when Operator::EXACT
    return !variation.nil? && (variation.variation_id == @variation_id)
  end
  Logging::KameleoonLogger.error(
    "Unexpected variation match type for '#{type}' condition: '#{@variation_match_type}'"
  )
  false
end