1
0
Fork 0
forked from OpenNeo/impress
impress/app/models/zone.rb

30 lines
937 B
Ruby
Raw Normal View History

2013-01-21 17:34:39 -08:00
class Zone < ActiveRecord::Base
translates :label, :plain_label
2010-09-08 19:49:39 -07:00
# When selecting zones that an asset occupies, we allow the zone to set
# whether or not the zone is "sometimes" occupied. This is false by default.
attr_writer :sometimes
2013-01-21 17:34:39 -08:00
scope :alphabetical, lambda {
with_translations(I18n.locale).order(Zone::Translation.arel_table[:label])
2013-01-21 17:34:39 -08:00
}
scope :includes_translations, lambda { includes(:translations) }
scope :with_plain_label, lambda { |label|
t = Zone::Translation.arel_table
includes(:translations).where(t[:plain_label].eq(Zone.plainify_label(label)))
}
scope :for_items, lambda { where(arel_table[:type_id].gt(1)) }
2010-09-08 19:49:39 -07:00
def uncertain_label
@sometimes ? "#{label} sometimes" : label
end
2013-01-21 17:34:39 -08:00
def self.all_plain_labels
select([:id]).includes(:translations).all.map(&:plain_label).uniq.sort
end
2012-10-08 19:20:18 -07:00
2013-01-21 17:34:39 -08:00
def self.plainify_label(label)
2013-01-26 07:54:29 -08:00
label.delete('\- /').parameterize
2012-10-08 19:20:18 -07:00
end
end