summaryrefslogtreecommitdiff
path: root/app/models/item.rb
blob: 5e60f0408abb8458cb5e99844fd2e44e1abad651 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Item < ApplicationRecord
  include HasWhatnot

  enum equip_slot: [:mainhand, :offhand, :head, :neck, :back, :torso, :grip,
                    :left_ring, :right_ring, :waist, :legs, :feet, :curio]
  validates :gid, :name, :description, presence: true
  validates :usable, inclusion: { in: [true, false] }

  def equipment?
    self.whatnot && self.whatnot[:equip_slots]&.any?
  end

  def equip_slots
    return [] unless self.equipment?
    self.whatnot[:equip_slots].map { |data| data.to_sym }
  end
end