Class: Kameleoon::Targeting::Tree Private
- Inherits:
-
Object
- Object
- Kameleoon::Targeting::Tree
- Defined in:
- lib/kameleoon/targeting/models.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
- #condition ⇒ Object private
- #left_child ⇒ Object private
- #or_operator ⇒ Object private
- #right_child ⇒ Object private
Instance Method Summary collapse
- #check(datas) ⇒ Object private
- #check_condition(datas, condition = @condition) ⇒ Object private
-
#initialize(or_operator = nil, left_child = nil, right_child = nil, condition = nil) ⇒ Tree
constructor
private
A new instance of Tree.
Constructor Details
#initialize(or_operator = nil, left_child = nil, right_child = nil, condition = nil) ⇒ Tree
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 Tree.
51 52 53 54 55 56 |
# File 'lib/kameleoon/targeting/models.rb', line 51 def initialize(or_operator = nil, left_child = nil, right_child = nil, condition = nil) @or_operator = Marshal.load(Marshal.dump(or_operator)) @left_child = left_child @right_child = right_child @condition = condition end |
Instance Attribute Details
#condition ⇒ 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.
49 50 51 |
# File 'lib/kameleoon/targeting/models.rb', line 49 def condition @condition end |
#left_child ⇒ 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.
49 50 51 |
# File 'lib/kameleoon/targeting/models.rb', line 49 def left_child @left_child end |
#or_operator ⇒ 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.
49 50 51 |
# File 'lib/kameleoon/targeting/models.rb', line 49 def or_operator @or_operator end |
#right_child ⇒ 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.
49 50 51 |
# File 'lib/kameleoon/targeting/models.rb', line 49 def right_child @right_child 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.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/kameleoon/targeting/models.rb', line 58 def check(datas) unless @condition.nil? is_targeted = check_condition(datas) else if @left_child.nil? is_left_child_targeted = true else is_left_child_targeted = @left_child.check(datas) end if is_left_child_targeted.nil? has_to_compute_right_child = true else has_to_compute_right_child = (is_left_child_targeted != @or_operator) end # Compute right child tree is_right_child_targeted = nil if has_to_compute_right_child if @right_child.nil? is_right_child_targeted = true else is_right_child_targeted = @right_child.check(datas) end end # Computing results if is_left_child_targeted.nil? if is_right_child_targeted == @or_operator is_targeted = Marshal.load(Marshal.dump(@or_operator)) #Deep copy else is_targeted = nil end else if is_left_child_targeted == @or_operator is_targeted = Marshal.load(Marshal.dump(@or_operator)) #Deep copy else if is_right_child_targeted == true is_targeted = true elsif is_right_child_targeted == false is_targeted = false else is_targeted = nil end end end end Marshal.load(Marshal.dump(is_targeted)) #Deep copy end |
#check_condition(datas, condition = @condition) ⇒ 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.
108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/kameleoon/targeting/models.rb', line 108 def check_condition(datas, condition = @condition) if condition.nil? is_targeted = true else is_targeted = condition.check(datas.call(condition.type)) unless condition.include return true if is_targeted.nil? is_targeted = !is_targeted end end Marshal.load(Marshal.dump(is_targeted)) # Deep copy end |