trugul-bot/models/raid.rb

24 lines
498 B
Ruby
Raw Normal View History

2015-04-25 13:17:47 -04:00
class Raid < ActiveRecord::Base
def money=(value)
value = value.to_s.gsub(/[$,]/, '').to_f
write_attribute(:money, value)
end
def soldiers=(value)
value = value.to_s.gsub(/[$,]/, '').to_f
write_attribute(:soldiers, value)
end
2015-04-28 10:12:01 -04:00
def self.for_user(username)
where('defender = ?', username)
end
def self.first_negative
where('money < 0').order(:created_at).first
end
2015-04-28 10:19:46 -04:00
def self.soldiers_lost_to_date(date)
where('date < ?', date).sum(:soldiers)
end
2015-04-25 13:17:47 -04:00
end