3 BANNERS.reject do |_k, v|
5 startdate = v[:startdate] && Date.parse(v[:startdate])
11 enddate = v[:enddate] && Date.parse(v[:enddate])
16 startdate&.future? || enddate&.past?
20 # returns the least recently seen banner that is not hidden
22 banners = active_banners
26 min_date = Date.new(9999, 1, 1)
28 banners.each do |k, v|
29 ckey = banner_cookie(v[:id]).to_sym
30 cval = cookies[ckey] || 0
31 next if cval == "hide"
33 # rotate all banner queue positions
35 cookies[ckey] = index - 1 if index.positive?
37 # pick banner with minimum queue position
38 next if index > min_index
40 # or if equal queue position, pick banner with soonest end date (i.e. next expiring)
41 end_date = Date.parse(v[:enddate])
42 next if index == min_index && end_date > min_date
50 unless banner_key.nil?
51 cookies[cookie_key] = banners.length # bump to end of queue
56 def banner_cookie(key)