From 1664ebe8eb7e14631987b99a2a4b7204ef2a4e75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 17 Sep 2021 18:36:00 +0200 Subject: [PATCH] Refactor code comparing polls --- app/models/poll.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/models/poll.rb b/app/models/poll.rb index a8f2b6810..7ef78b2a8 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -53,15 +53,7 @@ class Poll < ApplicationRecord def self.sort_for_list all.sort do |poll, another_poll| - if poll.geozone_restricted? == another_poll.geozone_restricted? - [poll.starts_at, poll.name] <=> [another_poll.starts_at, another_poll.name] - else - if poll.geozone_restricted? - 1 - else - -1 - end - end + [poll.weight, poll.starts_at, poll.name] <=> [another_poll.weight, another_poll.starts_at, another_poll.name] end end @@ -190,4 +182,12 @@ class Poll < ApplicationRecord def self.search(terms) pg_search(terms) end + + def weight + if geozone_restricted? + 100 + else + 0 + end + end end