diff options
author | Riyad Preukschas <riyad@informatik.uni-bremen.de> | 2012-09-11 18:47:59 +0400 |
---|---|---|
committer | Riyad Preukschas <riyad@informatik.uni-bremen.de> | 2012-09-11 18:47:59 +0400 |
commit | f7c70eaaedd196accbe8e952ddc4738a96b81998 (patch) | |
tree | 23eb57bbf340172d8ab541588dfefad7a5aa0627 /app/roles | |
parent | a5164ea2ed4e809cb4af7a070652ef2a6b19fbf3 (diff) |
Add *votes_in_percent
Diffstat (limited to 'app/roles')
-rw-r--r-- | app/roles/votes.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/app/roles/votes.rb b/app/roles/votes.rb index 3a584d8bebd..043a6feb777 100644 --- a/app/roles/votes.rb +++ b/app/roles/votes.rb @@ -4,11 +4,27 @@ module Votes notes.select(&:upvote?).size end + def upvotes_in_percent + if votes_count.zero? + 0 + else + 100.0 / votes_count * upvotes + end + end + # Return the number of -1 comments (downvotes) def downvotes notes.select(&:downvote?).size end + def downvotes_in_percent + if votes_count.zero? + 0 + else + 100.0 - upvotes_in_percent + end + end + # Return the total number of votes def votes_count upvotes + downvotes |