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