impress/app/models/zone.rb

24 lines
758 B
Ruby
Raw Normal View History

class Zone < ActiveRecord::Base
scope :alphabetical, -> { order(:label) }
scope :matching_label, ->(label) {
where(plain_label: Zone.plainify_label(label))
2013-01-21 17:34:39 -08:00
}
scope :for_items, -> { where(arel_table[:type_id].gt(1)) }
def as_json(options={})
super({only: [:id, :depth, :label]}.merge(options))
end
def is_commonly_used_by_items
# Zone metadata marks item zones with types 2, 3, and 4. But also, in
# practice, the Biology Effects zone (type 1, ID 4) has been used for a few
# items too. So, that's what we return true for!
# TODO: It'd probably be better to make this a database field?
[2, 3, 4].include?(type_id) || id == 4
end
2010-09-08 19:49:39 -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