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
Constant Summary collapse
- @@op =
This classvariable is part of a private API. You should avoid using this classvariable if possible, as it may be removed or be changed in the future.
{ Operator::REGULAR_EXPRESSION => method(:op_match), Operator::CONTAINS => method(:op_contains), Operator::EXACT => method(:op_exact), Operator::EQUAL => method(:op_equal), Operator::GREATER => method(:op_greater), Operator::LOWER => method(:op_lower), Operator::IS_TRUE => method(:op_is_true), Operator::IS_FALSE => method(:op_is_false), Operator::AMONG_VALUES => method(:op_among_values) }
Instance Attribute Summary
Attributes inherited from Condition
Class Method Summary collapse
- .op_among_values(values, value) ⇒ Object private
- .op_contains(values, value) ⇒ Object private
- .op_equal(values, value) ⇒ Object private
- .op_exact(values, value) ⇒ Object private
- .op_greater(values, value) ⇒ Object private
- .op_is_false(values, _value) ⇒ Object private
- .op_is_true(values, _value) ⇒ Object private
- .op_lower(values, value) ⇒ Object private
- .op_match(values, value) ⇒ Object private
Instance Method Summary collapse
- #check(list_data) ⇒ 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.
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/kameleoon/targeting/conditions/custom_datum.rb', line 66 def initialize(json_condition) super(json_condition) if json_condition['valueMatchType'].nil? raise Exception::NotFound.new('valueMatchType'), 'valueMatchType missed' end @type = ConditionType::CUSTOM_DATUM @index = json_condition['customDataIndex'] @operator = json_condition['valueMatchType'] @value = json_condition['value'] end |
Class Method Details
.op_among_values(values, value) ⇒ 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.
48 49 50 51 |
# File 'lib/kameleoon/targeting/conditions/custom_datum.rb', line 48 def op_among_values(values, value) all_matches = JSON.parse(value.to_s).map(&:to_s).to_set values.any? { |v| all_matches.include?(v) } end |
.op_contains(values, value) ⇒ 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.
20 21 22 |
# File 'lib/kameleoon/targeting/conditions/custom_datum.rb', line 20 def op_contains(values, value) values.any? { |v| v.to_s.include? value.to_s } end |
.op_equal(values, value) ⇒ 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.
28 29 30 |
# File 'lib/kameleoon/targeting/conditions/custom_datum.rb', line 28 def op_equal(values, value) values.any? { |v| v.to_f == value.to_f } end |
.op_exact(values, value) ⇒ 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.
24 25 26 |
# File 'lib/kameleoon/targeting/conditions/custom_datum.rb', line 24 def op_exact(values, value) values.include? value.to_s end |
.op_greater(values, value) ⇒ 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.
32 33 34 |
# File 'lib/kameleoon/targeting/conditions/custom_datum.rb', line 32 def op_greater(values, value) values.any? { |v| v.to_f > value.to_f } end |
.op_is_false(values, _value) ⇒ 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.
44 45 46 |
# File 'lib/kameleoon/targeting/conditions/custom_datum.rb', line 44 def op_is_false(values, _value) values.any? { |v| v.to_s == 'false' } end |
.op_is_true(values, _value) ⇒ 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.
40 41 42 |
# File 'lib/kameleoon/targeting/conditions/custom_datum.rb', line 40 def op_is_true(values, _value) values.any? { |v| v.to_s == 'true' } end |
.op_lower(values, value) ⇒ 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 |
# File 'lib/kameleoon/targeting/conditions/custom_datum.rb', line 36 def op_lower(values, value) values.any? { |v| v.to_f < value.to_f } end |
.op_match(values, value) ⇒ 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.
15 16 17 18 |
# File 'lib/kameleoon/targeting/conditions/custom_datum.rb', line 15 def op_match(values, value) re = Regexp.new(value.to_s) values.any? { |v| re.match(v) } end |
Instance Method Details
#check(list_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.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/kameleoon/targeting/conditions/custom_datum.rb', line 79 def check(list_data) is_targeted = false custom_data = list_data.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 @operation = @@op[@operator] unless @operation raise KameleoonError.new("Undefined operator #{@operator}"), "Undefined operator #{@operator}" end is_targeted = @operation.call(custom_data.values, @value) end is_targeted end |