make label_at more concise

This commit is contained in:
Christophe Robillard 2022-09-20 15:00:15 +02:00
parent 240f1b249f
commit f452e1014a

View file

@ -18,10 +18,8 @@ class Zone < ApplicationRecord
end
def label_at(date)
labels_a = labels.pluck(:designated_on, :name)
labels_a.find(-> { labels_a[-1] }) do |designated_on, _|
date >= designated_on
end.at(1)
label = labels.where('designated_on < ?', date)&.first || labels.last
label.name
end
def available_at?(date)