gitlabhq/app/roles/votes.rb

40 lines
680 B
Ruby
Raw Normal View History

2012-12-30 15:19:31 +01:00
# == Votes role
#
# Provides functionality to upvote/downvote entity
# based on +1 and -1 notes
#
# Used for Issue and Merge Request
#
2012-09-08 02:23:49 +02:00
module Votes
# Return the number of +1 comments (upvotes)
def upvotes
notes.select(&:upvote?).size
end
2012-09-08 02:30:47 +02:00
2012-09-11 16:47:59 +02:00
def upvotes_in_percent
if votes_count.zero?
0
else
100.0 / votes_count * upvotes
end
end
2012-09-08 02:30:47 +02:00
# Return the number of -1 comments (downvotes)
def downvotes
notes.select(&:downvote?).size
end
2012-09-08 02:37:29 +02:00
2012-09-11 16:47:59 +02:00
def downvotes_in_percent
if votes_count.zero?
0
else
100.0 - upvotes_in_percent
end
end
2012-09-08 02:37:29 +02:00
# Return the total number of votes
def votes_count
upvotes + downvotes
end
end