Class: Kameleoon::Targeting::TargetExperimentCondition Private

Inherits:
Condition
  • Object
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

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)

  @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
# File 'lib/kameleoon/targeting/conditions/target_experiment_condition.rb', line 21

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

  variation = data.variations_storage&.get(@experiment_id)
  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