Files
grecia/app/models/poll/officer.rb
Javi Martín db97f9d08c Add and apply rubocop rules for empty lines
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
2019-10-24 17:11:47 +02:00

37 lines
1.2 KiB
Ruby

class Poll
class Officer < ApplicationRecord
belongs_to :user
has_many :officer_assignments, class_name: "Poll::OfficerAssignment"
has_many :shifts, class_name: "Poll::Shift"
has_many :failed_census_calls, foreign_key: :poll_officer_id
validates :user_id, presence: true, uniqueness: true
def name
user&.name || I18n.t("shared.author_info.author_deleted")
end
def email
user&.email || I18n.t("shared.author_info.email_deleted")
end
def voting_days_assigned_polls
officer_assignments.voting_days.includes(booth_assignment: :poll).
map(&:booth_assignment).
map(&:poll).uniq.compact.
sort { |x, y| y.ends_at <=> x.ends_at }
end
def final_days_assigned_polls
officer_assignments.final.includes(booth_assignment: :poll).
map(&:booth_assignment).
map(&:poll).uniq.compact.
sort { |x, y| y.ends_at <=> x.ends_at }
end
def todays_booths
officer_assignments.by_date(Date.current).map(&:booth).uniq
end
end
end