2021-12-01 20:00:29 +01:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: zones
|
|
|
|
#
|
|
|
|
# id :bigint not null, primary key
|
2022-02-04 14:40:16 +01:00
|
|
|
# acronym :string not null
|
2021-12-01 20:00:29 +01:00
|
|
|
# label :string
|
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
|
|
|
#
|
|
|
|
class Zone < ApplicationRecord
|
|
|
|
validates :acronym, presence: true, uniqueness: true
|
2022-08-11 19:05:12 +02:00
|
|
|
has_many :labels, -> { order(designated_on: :desc) }, class_name: 'ZoneLabel', inverse_of: :zone
|
2021-12-18 17:28:49 +01:00
|
|
|
has_many :procedures, -> { order(published_at: :desc) }, inverse_of: :zone
|
2022-08-11 19:05:12 +02:00
|
|
|
|
|
|
|
def label
|
|
|
|
labels.first.name
|
|
|
|
end
|
2022-08-12 12:24:47 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
end
|
2021-12-01 20:00:29 +01:00
|
|
|
end
|