-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathequipment_profile.rb
More file actions
26 lines (21 loc) · 935 Bytes
/
equipment_profile.rb
File metadata and controls
26 lines (21 loc) · 935 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class EquipmentProfile < ApplicationRecord
has_and_belongs_to_many :eventdates
validates_presence_of :description, :category, :shortname
scope :active, -> { where(defunct: false) }
scope :categories, -> { active.order(:category => :asc).select(:category).distinct.pluck(:category) }
scope :subcategories, -> (category) { active.order(:subcategory => :asc).where(category: category).where.not(subcategory: nil).select(:subcategory).distinct.pluck(:subcategory) }
scope :category, -> (category) { active.where(category: category, subcategory: nil) }
scope :subcategory, -> (category, subcategory) { active.where(category: category, subcategory: subcategory) }
before_validation :null_subcategory
def full_category
if subcategory
"#{category} - #{subcategory}"
else
category
end
end
private
def null_subcategory
self.subcategory = nil if subcategory.blank?
end
end