Files
nairobi/app/models/poll/ballot.rb
2019-04-10 18:29:01 +02:00

37 lines
772 B
Ruby

class Poll::Ballot < ActiveRecord::Base
belongs_to :ballot_sheet, class_name: Poll::BallotSheet
validates :ballot_sheet_id, presence: true
def verify
investments.each do |investment_id|
add_investment(investment_id)
end
end
def add_investment(investment_id)
investment = find_investment(investment_id)
if investment.present? && not_already_added?(investment)
ballot.add_investment(investment)
end
end
def investments
data.split(",")
end
def ballot
Budget::Ballot.where(poll_ballot: self).first
end
def find_investment(investment_id)
ballot.budget.investments.where(id: investment_id).first
end
def not_already_added?(investment)
ballot.lines.where(investment: investment).blank?
end
end