Class: Kameleoon::Targeting::CustomDatum Private

Inherits:
Condition
  • Object
show all
Includes:
Exception
Defined in:
lib/kameleoon/targeting/conditions/custom_datum.rb

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.

Instance Attribute Summary collapse

Attributes inherited from Condition

#include, #type

Instance Method Summary collapse

Constructor Details

#initialize(json_condition) ⇒ CustomDatum

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



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/kameleoon/targeting/conditions/custom_datum.rb', line 12

def initialize(json_condition)
  if json_condition['customDataIndex'].nil?
    raise Exception::NotFoundError.new('customDataIndex')
  end
  @index = json_condition['customDataIndex']

  if json_condition['valueMatchType'].nil?
    raise Exception::NotFoundError.new('valueMatchType')
  end
  @operator = json_condition['valueMatchType']

  if json_condition['value'].nil?
    raise Exception::NotFoundError.new('value')
  end
  @value = json_condition['value']

  @type = ConditionType::CUSTOM_DATUM

  if json_condition['include'].nil?
    raise Exception::NotFoundError.new('include')
  end
  @include = json_condition['include']
end

Instance Attribute Details

#indexObject

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.



11
12
13
# File 'lib/kameleoon/targeting/conditions/custom_datum.rb', line 11

def index
  @index
end

#operatorObject

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.



11
12
13
# File 'lib/kameleoon/targeting/conditions/custom_datum.rb', line 11

def operator
  @operator
end

#valueObject

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.



11
12
13
# File 'lib/kameleoon/targeting/conditions/custom_datum.rb', line 11

def value
  @value
end

Instance Method Details

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



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/kameleoon/targeting/conditions/custom_datum.rb', line 36

def check(datas)
  is_targeted = false
  custom_data = datas.select { |data| data.instance == DataType::CUSTOM && data.id == @index }.first
  if custom_data.nil?
    is_targeted = (@operator == Operator::UNDEFINED.to_s)
  else
    case @operator
    when Operator::MATCH.to_s
      if Regexp.new(@value.to_s).match(custom_data.value.to_s)
        is_targeted = true
      end
    when Operator::CONTAINS.to_s
      if custom_data.value.to_s.include? @value
        is_targeted = true
      end
    when Operator::EXACT.to_s
      if custom_data.value.to_s == @value.to_s
        is_targeted = true
      end
    when Operator::EQUAL.to_s
      if custom_data.value.to_f == @value.to_f
        is_targeted = true
      end
    when Operator::GREATER.to_s
      if custom_data.value.to_f > @value.to_f
        is_targeted = true
      end
    when Operator::LOWER.to_s
      if custom_data.value.to_f < @value.to_f
        is_targeted = true
      end
    when Operator::IS_TRUE.to_s
      if custom_data.value == true
        is_targeted = true
      end
    when Operator::IS_FALSE.to_s
      if custom_data.value == false
        is_targeted = true
      end
    else
      raise KameleoonError.new("Undefined operator " + @operator.to_s)
    end
  end
  is_targeted
end