Module: Juixe::Acts::Voteable::InstanceMethods

Defined in:
lib/acts_as_voteable.rb

Overview

This module contains instance methods

Instance Method Summary collapse

Instance Method Details

#voted_by?(voter) ⇒ Boolean

Returns:

  • (Boolean)


100
101
102
103
104
105
106
107
108
# File 'lib/acts_as_voteable.rb', line 100

def voted_by?(voter)
  rtn = false
  if voter
    self.votes.each { |v|
      rtn = true if (voter.id == v.voter_id && voter.class.name == v.voter_type)
    }
  end
  rtn
end

#voters_who_votedObject



92
93
94
95
96
97
98
# File 'lib/acts_as_voteable.rb', line 92

def voters_who_voted
  voters = []
  self.votes.each { |v|
    voters << v.voter
  }
  voters
end

#votes_againstObject



80
81
82
83
84
85
# File 'lib/acts_as_voteable.rb', line 80

def votes_against
  Vote.count(:all, :conditions => [
    "voteable_id = ? AND voteable_type = ? AND vote = ?",
    id, self.class.name, false
  ])
end

#votes_countObject

Same as voteable.votes.size



88
89
90
# File 'lib/acts_as_voteable.rb', line 88

def votes_count
  self.votes.size
end

#votes_forObject



73
74
75
76
77
78
# File 'lib/acts_as_voteable.rb', line 73

def votes_for
  Vote.count(:all, :conditions => [
    "voteable_id = ? AND voteable_type = ? AND vote = ?",
    id, self.class.name, true
  ])
end