We were very inconsistent regarding these rules. Personally I prefer no empty lines around blocks, clases, etc... as recommended by the Ruby style guide [1], and they're the default values in rubocop, so those are the settings I'm applying. The exception is the `private` access modifier, since we were leaving empty lines around it most of the time. That's the default rubocop rule as well. Personally I don't have a strong preference about this one. [1] https://rubystyle.guide/#empty-lines-around-bodies
36 lines
764 B
Ruby
36 lines
764 B
Ruby
class Poll::Ballot < ApplicationRecord
|
|
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.find_by(poll_ballot: self)
|
|
end
|
|
|
|
def find_investment(investment_id)
|
|
ballot.budget.investments.find_by(id: investment_id)
|
|
end
|
|
|
|
def not_already_added?(investment)
|
|
ballot.lines.where(investment: investment).blank?
|
|
end
|
|
end
|