Add *votes_in_percent
This commit is contained in:
parent
a5164ea2ed
commit
f7c70eaaed
2 changed files with 66 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue