2012-09-07 20:23:49 -04:00
|
|
|
module Votes
|
2012-06-07 08:44:57 -04:00
|
|
|
# Return the number of +1 comments (upvotes)
|
|
|
|
def upvotes
|
|
|
|
notes.select(&:upvote?).size
|
|
|
|
end
|
2012-09-07 20:30:47 -04:00
|
|
|
|
2012-09-11 10:47:59 -04:00
|
|
|
def upvotes_in_percent
|
|
|
|
if votes_count.zero?
|
|
|
|
0
|
|
|
|
else
|
|
|
|
100.0 / votes_count * upvotes
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-07 20:30:47 -04:00
|
|
|
# Return the number of -1 comments (downvotes)
|
|
|
|
def downvotes
|
|
|
|
notes.select(&:downvote?).size
|
|
|
|
end
|
2012-09-07 20:37:29 -04:00
|
|
|
|
2012-09-11 10:47:59 -04:00
|
|
|
def downvotes_in_percent
|
|
|
|
if votes_count.zero?
|
|
|
|
0
|
|
|
|
else
|
|
|
|
100.0 - upvotes_in_percent
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-07 20:37:29 -04:00
|
|
|
# Return the total number of votes
|
|
|
|
def votes_count
|
|
|
|
upvotes + downvotes
|
|
|
|
end
|
2012-06-07 08:44:57 -04:00
|
|
|
end
|