Module: Neuron::Client::AdCalculations

Included in:
Ad
Defined in:
lib/neuron-client/model/ad_calculations.rb

Instance Method Summary collapse

Instance Method Details

#active?Boolean

This module expects the following methods to be defined: start_datetime (Time, String, or nil) end_datetime (Time, String, or nil) time_zone (String) day_partitions (String, or nil, length = 7*24, matches /^[TF]+$/) daily_cap (FixNum, or nil) overall_cap (FixNum, or nil) ideal_impressions_per_hour (Number, or nil) total_impressed (Integer, >= 0) today_impressed (Integer, >= 0)

Returns:

  • (Boolean)


15
16
17
# File 'lib/neuron-client/model/ad_calculations.rb', line 15

def active?
  calculate_active?(Time.now, total_impressed, today_impressed)
end

#calculate_active?(time, total, today) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
# File 'lib/neuron-client/model/ad_calculations.rb', line 23

def calculate_active?(time, total, today)
  time = time.in_time_zone(time_zone)
  return false unless within_date_range?(time)
  return false if partitioned? && !partitioned_hour?(time)
  !cap_met?(total, today)
end

#calculate_pressure(time, total, today, active = nil) ⇒ Object

Set the optional “active” parameter to true or false if you already know



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/neuron-client/model/ad_calculations.rb', line 31

def calculate_pressure(time, total, today, active=nil)
  return nil if active == false
  return nil unless active || calculate_active?(time,total,today)
  time = time.in_time_zone(time_zone)
  if daily_capped?
    if daily_cap_precludes_overall_cap?(time,total,today)
      calculate_overall_pressure(time, total)
    else
      calculate_today_pressure(time, today)
    end
  elsif overall_pressure_exists?
    calculate_overall_pressure(time, total)
  else
    (ideal_impressions_per_hour || 1.0).to_f
  end
end

#pressureObject



19
20
21
# File 'lib/neuron-client/model/ad_calculations.rb', line 19

def pressure
  calculate_pressure(Time.now, total_impressed, today_impressed)
end