1 # frozen_string_literal: true
5 BANNERS.reject do |_k, v|
7 startdate = v[:startdate] && Date.parse(v[:startdate])
13 enddate = v[:enddate] && Date.parse(v[:enddate])
18 wrong_locale = v[:locales]&.exclude?(I18n.locale.to_s)
19 remote_country = params[:country] || OSM.ip_to_country(request.remote_ip)
20 wrong_country = v[:countries]&.exclude?(remote_country)
22 startdate&.future? || enddate&.past? || wrong_locale || wrong_country
26 # returns the least recently seen banner that is not hidden
28 banners = active_banners
32 min_date = Date.new(9999, 1, 1)
34 banners.each do |k, v|
35 ckey = banner_cookie(v[:id]).to_sym
36 cval = cookies[ckey] || 0
37 next if cval == "hide"
39 # rotate all banner queue positions
41 cookies[ckey] = index - 1 if index.positive?
43 # pick banner with minimum queue position
44 next if index > min_index
46 # or if equal queue position, pick banner with soonest end date (i.e. next expiring)
47 end_date = Date.parse(v[:enddate])
48 next if index == min_index && end_date > min_date
56 unless banner_key.nil?
57 cookies[cookie_key] = banners.length # bump to end of queue
62 def banner_cookie(key)