Class: Kameleoon::Targeting::TargetExperiment Private

Inherits:
Condition
  • Object
show all
Includes:
Exception
Defined in:
lib/kameleoon/targeting/conditions/target_experiment.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

#include, #type

Instance Method Summary collapse

Constructor Details

#initialize(json_condition) ⇒ TargetExperiment

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 TargetExperiment.

Raises:



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/kameleoon/targeting/conditions/target_experiment.rb', line 13

def initialize(json_condition)
  super(json_condition)

  raise Exception::NotFound.new('experiment'), 'experiment missed' if json_condition['experiment'].nil?
  if json_condition['variationMatchType'].nil?
    raise Exception::NotFound.new('variationMatchType'), 'variationMatchType missed'
  end

  @experiment = json_condition['experiment']
  @operator = json_condition['variationMatchType']
  @variation = json_condition['variation']
end

Instance Method Details

#check(variation_storage) ⇒ 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.



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

def check(variation_storage)
  is_targeted = false
  variation_storage_exist = !variation_storage.nil? && !variation_storage.empty?
  saved_variation = variation_storage[@experiment] unless variation_storage.nil?
  case @operator
  when Operator::EXACT
    is_targeted = variation_storage_exist && saved_variation == @variation
  when Operator::ANY
    is_targeted = variation_storage_exist
  end
  is_targeted
end