Module: ActsRateable::LocalInstanceMethods

Defined in:
lib/acts_rateable/acts_rateable.rb

Instance Method Summary collapse

Instance Method Details

#has_rated?(resource) ⇒ Boolean

Checks wheter a user rated a resource. Returns the rating if true, otherwise returns false.

Returns:

  • (Boolean)


52
53
54
# File 'lib/acts_rateable/acts_rateable.rb', line 52

def has_rated?( resource )
  ActsRateable::Rate.rated?(resource, self)
end

#rate(resource, value) ⇒ Object

Rates a resource by an author with a given value.



57
58
59
# File 'lib/acts_rateable/acts_rateable.rb', line 57

def rate( resource, value )
    ActsRateable::Rate.create(self, resource, value)
end

#rated_by?(author) ⇒ Boolean

Checks wheter a resource has been rated by a user. Returns the rating if true, otherwise returns false.

Returns:

  • (Boolean)


47
48
49
# File 'lib/acts_rateable/acts_rateable.rb', line 47

def rated_by?( author )
  ActsRateable::Rate.rated?(self, author)
end

#variation(author) ⇒ Object



42
43
44
# File 'lib/acts_rateable/acts_rateable.rb', line 42

def variation( author )
  rated_by?(author) ? (rated_by?(author).value/self.rating['estimate']) : nil
end