Refactor web and booth votes calculations

This commit is contained in:
Javi Martín
2019-01-04 19:15:44 +01:00
parent 0e2e5a27c3
commit 7dbe1dce86

View File

@@ -22,20 +22,16 @@ class Poll::Stats
total_participants_web + total_participants_booth total_participants_web + total_participants_booth
end end
def total_participants_web %i[web booth].each do |channel|
total_web_valid + total_web_white + total_web_null define_method :"total_participants_#{channel}" do
send(:"total_#{channel}_valid") +
send(:"total_#{channel}_white") +
send(:"total_#{channel}_null")
end end
def total_participants_web_percentage define_method :"total_participants_#{channel}_percentage" do
calculate_percentage(total_participants_web, total_participants) calculate_percentage(send(:"total_participants_#{channel}"), total_participants)
end end
def total_participants_booth
total_booth_valid + total_booth_white + total_booth_null
end
def total_participants_booth_percentage
calculate_percentage(total_participants_booth, total_participants)
end end
def total_web_valid def total_web_valid