1
0
Fork 0
dokkan-data-rails/app/models/card.rb

68 lines
1.5 KiB
Ruby
Raw Normal View History

2015-10-06 13:55:12 -04:00
class Card < ActiveRecord::Base
has_paper_trail
2015-10-21 10:33:48 -04:00
after_create :set_stat_types
2015-10-21 09:27:49 -04:00
2015-10-06 13:55:12 -04:00
belongs_to :character
belongs_to :rarity
belongs_to :type
belongs_to :leader_skill
belongs_to :passive_skill
belongs_to :super_attack
belongs_to :awaken_type
2015-10-08 11:45:05 -04:00
belongs_to :dokkan_card, class_name: 'Card', foreign_key: :dokkan_id
2015-10-06 13:55:12 -04:00
2015-11-03 14:36:44 -05:00
has_and_belongs_to_many :links, counter_cache: true
2015-10-06 13:55:12 -04:00
2015-10-14 11:24:15 -04:00
has_many :evidences
2015-10-20 17:39:36 -04:00
belongs_to :hp_stat, class_name: 'Stat'
belongs_to :atk_stat, class_name: 'Stat'
belongs_to :def_stat, class_name: 'Stat'
accepts_nested_attributes_for :hp_stat
accepts_nested_attributes_for :atk_stat
accepts_nested_attributes_for :def_stat
2015-10-06 13:55:12 -04:00
delegate :name, to: :character, prefix: false
2015-10-08 12:40:31 -04:00
validates :title, presence: true
2015-10-06 13:55:12 -04:00
validates :character, presence: true
validates :gameid, presence: true,
numericality: { only_integer: true },
length: { is: 7 }
validates :rarity, presence: true
validates :type, presence: true
validates :awaken_type, presence: true
2015-10-08 13:08:45 -04:00
default_scope { order(:gameid) }
2015-11-03 16:21:41 -05:00
scope :new_this_week, -> { where('created_at > ?', 1.week.ago) }
2015-10-06 13:55:12 -04:00
def dokkan?
2015-10-08 11:45:05 -04:00
dokkan_id != nil
end
def full_name
2015-10-08 12:40:31 -04:00
"#{title} #{character.name}"
2015-10-08 11:45:05 -04:00
end
def icon
"card_#{gameid}_thumb.png"
2015-10-06 13:55:12 -04:00
end
2015-10-21 09:27:49 -04:00
2015-11-03 16:15:20 -05:00
def self.verified
Card.where(verified: true)
end
2015-10-21 09:27:49 -04:00
private
def set_stat_types
self.hp_stat.stat_type_id = 1
self.atk_stat.stat_type_id = 2
self.def_stat.stat_type_id = 3
2015-10-21 10:33:48 -04:00
self.save
2015-10-21 09:27:49 -04:00
end
2015-10-06 13:55:12 -04:00
end