Class: Kameleoon::Targeting::TimeElapsedSinceVisitCondition Private

Inherits:
NumberCondition show all
Defined in:
lib/kameleoon/targeting/conditions/time_elapsed_since_visit_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) ⇒ TimeElapsedSinceVisitCondition

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



10
11
12
13
14
# File 'lib/kameleoon/targeting/conditions/time_elapsed_since_visit_condition.rb', line 10

def initialize(json_condition)
  count_in_millis = json_condition['countInMillis']
  super(json_condition, count_in_millis)
  @is_first_visit = @type == Kameleoon::Targeting::ConditionType::FIRST_VISIT
end

Instance Method Details

#check(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.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/kameleoon/targeting/conditions/time_elapsed_since_visit_condition.rb', line 16

def check(data)
  return false unless data.is_a?(Kameleoon::VisitorVisits) && !@condition_value.nil?

  previous_visits_count = data.previous_visit_timestamps.count
  if previous_visits_count >= 1
    now = (Time.now.to_f * 1000).to_i # ... * 1000 for convert seconds to milliseconds
    visit_time = data.previous_visit_timestamps[@is_first_visit ? previous_visits_count - 1 : 0]
    return check_targeting(now - visit_time)
  end
  false
end