diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2012-09-12 10:08:19 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2012-09-12 10:08:19 +0400 |
commit | 40eec08c99fe29963afed0f073b7bdbbfe31ac59 (patch) | |
tree | d4779b49b29c91cd65162e7a5e9ea875b7e3c8ba /app/roles | |
parent | d8f6d38d39868426902ffbad9c232b7748a4288f (diff) | |
parent | 0bfcc574b660108646bd2c99a611163a0c847251 (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.rb | 6 | ||||
-rw-r--r-- | app/roles/votes.rb | 32 |
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 |