about summary refs log tree commit diff stats
path: root/app/models/move.rb
blob: cbc84228e7475ce36a6462f7c45413116d70a00a (plain) (blame)
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
27
28
29
30
31
class Move < ApplicationRecord
  extend Enumerize

  has_many :revision_moves
  has_many :revisions, through: :revision_moves

  validates :name, presence: true, uniqueness: true

  validates :pp, presence: true,
    numericality: { greater_than_or_equal_to: 1, only_integer: true }

  TYPES = [:normal, :fighting, :flying, :poison, :ground,
    :rock, :bug, :ghost, :steel, :mystery, :fire, :water, :grass, :electric,
    :psychic, :ice, :dragon, :dark]

  validates :move_type, presence: true
  enumerize :move_type, in: TYPES, predicates: true

  validates :rs_description, presence: true
  validates :frlg_description, presence: true

  def description(game)
    if game == :emerald and not emerald_description.nil?
      emerald_description
    elsif game == :firered or game == :leafgreen
      frlg_description
    else
      rs_description
    end
  end
end