3 BANNERS.reject do |_k, v|
6 parsed = enddate && Date.parse(enddate)
10 !parsed.is_a?(Date) || (parsed.is_a?(Date) && parsed.past?)
14 # returns the least recently seen banner that is not hidden
16 banners = active_banners
20 min_date = Date.new(9999, 1, 1)
22 banners.each do |k, v|
23 ckey = banner_cookie(v[:id]).to_sym
24 cval = cookies[ckey] || 0
25 next if cval == "hide"
27 # rotate all banner queue positions
29 cookies[ckey] = index - 1 if index.positive?
31 # pick banner with mininum queue position
32 next if index > min_index
34 # or if equal queue position, pick banner with soonest end date (i.e. next expiring)
35 end_date = Date.parse(v[:enddate])
36 next if index == min_index && end_date > min_date
44 unless banner_key.nil?
45 cookies[cookie_key] = banners.length # bump to end of queue
50 def banner_cookie(key)