Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app/roles
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-09-12 10:08:19 +0400
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-09-12 10:08:19 +0400
commit40eec08c99fe29963afed0f073b7bdbbfe31ac59 (patch)
treed4779b49b29c91cd65162e7a5e9ea875b7e3c8ba /app/roles
parentd8f6d38d39868426902ffbad9c232b7748a4288f (diff)
parent0bfcc574b660108646bd2c99a611163a0c847251 (diff)
Merge pull request #1409 from riyad/update-votes
Update votes for issues and merge requests
Diffstat (limited to 'app/roles')
-rw-r--r--app/roles/upvote.rb6
-rw-r--r--app/roles/votes.rb32
2 files changed, 32 insertions, 6 deletions
diff --git a/app/roles/upvote.rb b/app/roles/upvote.rb
deleted file mode 100644
index 7efa6f20cfc..00000000000
--- a/app/roles/upvote.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-module Upvote
- # Return the number of +1 comments (upvotes)
- def upvotes
- notes.select(&:upvote?).size
- end
-end
diff --git a/app/roles/votes.rb b/app/roles/votes.rb
new file mode 100644
index 00000000000..043a6feb777
--- /dev/null
+++ b/app/roles/votes.rb
@@ -0,0 +1,32 @@
+module Votes
+ # Return the number of +1 comments (upvotes)
+ def upvotes
+ 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
+ end
+end