summaryrefslogtreecommitdiff
path: root/app/models/item.rb
blob: 1ef5d7dbda303b3e1aa7ad637e852888855727e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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

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

  def usable?
    self.whatnot && self.whatnot[:use_effects]&.any?
  end

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