Class: Kameleoon::Targeting::CustomDatum Private
- Includes:
- Exception
- Defined in:
- lib/kameleoon/targeting/conditions/custom_datum.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.
CustomDatum represents an instance of Custom Data condition from back office
Instance Attribute Summary
Attributes inherited from Condition
Instance Method Summary collapse
- #check(datas) ⇒ Object private
-
#initialize(json_condition) ⇒ CustomDatum
constructor
private
A new instance of CustomDatum.
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.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/kameleoon/targeting/conditions/custom_datum.rb', line 14 def initialize(json_condition) super(json_condition) @index = json_condition['customDataIndex'] if json_condition['valueMatchType'].nil? raise Exception::NotFound.new('valueMatchType'), 'valueMatchType missed' end @operator = json_condition['valueMatchType'] @value = json_condition['value'] @type = ConditionType::CUSTOM_DATUM if json_condition['include'].nil? && json_condition['isInclude'].nil? raise Exception::NotFound.new('include / isInclude missed'), 'include / isInclude missed' end @include = json_condition['include'] || json_condition['isInclude'] @op = { Operator::MATCH.to_s => method(:op_match), Operator::CONTAINS.to_s => method(:op_contains), Operator::EXACT.to_s => method(:op_exact), Operator::EQUAL.to_s => method(:op_equal), Operator::GREATER.to_s => method(:op_greater), Operator::LOWER.to_s => method(:op_lower), Operator::IS_TRUE.to_s => method(:op_is_true), Operator::IS_FALSE.to_s => method(:op_is_false), Operator::AMONG_VALUES.to_s => method(:op_among_values), }[@operator] 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.
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/kameleoon/targeting/conditions/custom_datum.rb', line 47 def check(datas) is_targeted = false custom_data = datas.select { |data| data.instance == DataType::CUSTOM && data.id == @index }.last if custom_data.nil? is_targeted = (@operator == Operator::UNDEFINED.to_s) elsif @operator != Operator::UNDEFINED.to_s raise KameleoonError.new("Undefined operator #{@operator}"), "Undefined operator #{@operator}" if @op.nil? is_targeted = @op.call(custom_data.values) end is_targeted end |