README.md in voting-0.1.0 vs README.md in voting-0.2.0

- old
+ new

@@ -1,10 +1,11 @@ # Voting [![Build Status](https://travis-ci.org/wbotelhos/voting.svg)](https://travis-ci.org/wbotelhos/voting) [![Gem Version](https://badge.fury.io/rb/voting.svg)](https://badge.fury.io/rb/voting) -[![LiberPay](https://img.shields.io/badge/donate-%3C3-brightgreen.svg)](https://liberapay.com/wbotelhos) +[![Maintainability](https://api.codeclimate.com/v1/badges/dcdf51e3093148c5ac6a/maintainability)](https://codeclimate.com/github/wbotelhos/voting/maintainability) +[![Support](https://img.shields.io/badge/donate-%3C3-brightgreen.svg)](https://liberapay.com/wbotelhos) A Binomial proportion confidence interval voting system with scope and cache enabled. ## Description @@ -113,10 +114,17 @@ resource = Comment.last author.voted? resource ``` +If you want to know if the vote was `positive` or `negative`, just pass a symbol about it: + +```ruby +author.voted? resource, :negative +author.voted? resource, :positive +``` + ### votes You can retrieve all votes received by some resource: ```ruby @@ -180,50 +188,70 @@ ```ruby voting as: :author ``` -### Scoping +### Alias -If you need to warm up a record with scope, you need to setup the `scoping` relation. +You can to use alias to directly call `vote` with positive or negative data. ```ruby -class Resource < ApplicationRecord - voting scoping: :categories -end +author = Author.last +resource = Comment.last + +author.up resource # +1 +author.down resource # -1 ``` -Now, when a resource is created, the cache will be generated for each related `category` as `scopeable`. +#### Options -# Toggle +`down`: makes a negative vote; +`up`: makes a positive vote; + +### Toggle + The toggle functions works out of box, so if you vote up twice or vote twice down, the vote will be canceled. When you do that, the vote record is **not destroyed** instead, it receives zero on `negative` and `positive` column. -# Alias +### Scope -You can to use alias to directly call `vote` with positive or negative data. +All methods accepts a `scope` param to be persisted with the vote or to be searched: ```ruby -author = Author.last -resource = Comment.last +category = Category.last -author.up resource # +1 -author.down resource # -1 +author.down resource, scope: category +author.up resource, scope: category +author.vote resource, 1, scope: category +author.vote_for resource, scope: category +author.voted resource, scope: category +author.voted? resource, :negative, scope: category +author.voted? resource, :positive, scope: category + +resource.votes scope: category +author .voted scope: category +resource.votign scope: category ``` -### Options +### Scoping -`down`: makes a negative vote; +If you need to warm up a record with scope, you need to setup the `scoping` relation. -`up`: makes a positive vote; +```ruby +class Resource < ApplicationRecord + voting scoping: :categories +end +``` +Now, when a resource is created, the cache will be generated for each related `category` as `scopeable`. + ### References - [Evan Miller](https://www.evanmiller.org/how-not-to-sort-by-average-rating.html) - [Jonathan Landy](http://efavdb.com/ranking-revisited) - [Wilson Score Interval](https://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval#Wilson_score_interval) - [How to Count Thumb-Ups and Thumb-Downs](http://www.dcs.bbk.ac.uk/~dell/publications/dellzhang_ictir2011.pdf) ## Love it! -Via [PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=X8HEP2878NDEG&item_name=voting) or [LiberPay](https://liberapay.com/wbotelhos). Thanks! (: +Via [PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=X8HEP2878NDEG&item_name=voting) or [Support](https://liberapay.com/wbotelhos). Thanks! (: