2023-08-02 16:05:02 -07:00
|
|
|
class Campaign < ApplicationRecord
|
2014-09-11 15:40:37 -07:00
|
|
|
has_many :donations
|
|
|
|
|
|
|
|
def progress_percent
|
2014-09-11 15:47:42 -07:00
|
|
|
[(progress.to_f / goal) * 100, 100].min
|
2014-09-11 15:40:37 -07:00
|
|
|
end
|
|
|
|
|
2015-09-22 22:19:43 -07:00
|
|
|
def remaining
|
|
|
|
goal - progress
|
|
|
|
end
|
|
|
|
|
2015-09-22 22:40:51 -07:00
|
|
|
def complete?
|
|
|
|
progress >= goal
|
|
|
|
end
|
|
|
|
|
2014-09-11 15:40:37 -07:00
|
|
|
def self.current
|
|
|
|
self.where(active: true).first or
|
|
|
|
raise ActiveRecord::RecordNotFound.new("no current campaign")
|
|
|
|
end
|
|
|
|
end
|