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.
- #to_s ⇒ Object private
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.
65 66 67 68 69 70 |
# File 'lib/kameleoon/targeting/models.rb', line 65 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.
50 51 52 |
# File 'lib/kameleoon/targeting/models.rb', line 50 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.
50 51 52 |
# File 'lib/kameleoon/targeting/models.rb', line 50 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.
50 51 52 |
# File 'lib/kameleoon/targeting/models.rb', line 50 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.
50 51 52 |
# File 'lib/kameleoon/targeting/models.rb', line 50 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.
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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/kameleoon/targeting/models.rb', line 72 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.
122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/kameleoon/targeting/models.rb', line 122 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 |
#to_s ⇒ 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.
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/kameleoon/targeting/models.rb', line 52 def to_s print("or_operator: #{@or_operator}\n") print("condition: #{@condition}") unless @left_child.nil? print('\nLeft child:\n ') @left_child.to_s end unless @right_child.nil? print('\nright child:\n ') @right_child.to_s end end |