Class: Kameleoon::Targeting::PreviousPageCondition Private

Inherits:
StringValueCondition show all
Defined in:
lib/kameleoon/targeting/conditions/previous_page_condition.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

Attributes inherited from Condition

#id, #include, #type

Instance Method Summary collapse

Constructor Details

#initialize(json_condition) ⇒ PreviousPageCondition

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



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

def initialize(json_condition)
  super(json_condition, json_condition['url'])
end

Instance Method Details

#check(page_view_visit_storage) ⇒ 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
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/kameleoon/targeting/conditions/previous_page_condition.rb', line 15

def check(page_view_visit_storage)
  is_targeted = false
  if page_view_visit_storage.is_a?(Kameleoon::DataManager::DataMapStorage)
    most_recent_visit = nil
    second_most_recent_visit = nil
    page_view_visit_storage.enumerate do |visit|
      return false unless visit.is_a?(Kameleoon::DataManager::PageViewVisit)
      if most_recent_visit == nil || visit.last_timestamp > most_recent_visit.last_timestamp
        second_most_recent_visit = most_recent_visit
        most_recent_visit = visit
      elsif second_most_recent_visit == nil || visit.last_timestamp > second_most_recent_visit.last_timestamp
        second_most_recent_visit = visit
      end
    end
    is_targeted = second_most_recent_visit != nil && check_targeting(second_most_recent_visit.page_view.url)
  end
  is_targeted
end