Module: SanteyVote::Voteable::InstanceMethods

Defined in:
lib/santey_vote/voteable.rb

Instance Method Summary collapse

Instance Method Details

#users_who_votedObject



48
49
50
51
52
53
54
# File 'lib/santey_vote/voteable.rb', line 48

def users_who_voted
  users = []
  self.votes.each { |v|
    users << v.user
  }
  users
end

#voted_by_user?(user) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
59
60
61
62
63
64
# File 'lib/santey_vote/voteable.rb', line 56

def voted_by_user?(user)
  rtn = false
  if user
    self.votes.each { |v|
      rtn = true if user.id == v.user_id
    }
  end
  rtn
end

#votes_againstObject



35
36
37
38
39
40
41
# File 'lib/santey_vote/voteable.rb', line 35

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

#votes_countObject

Same as voteable.votes.size



44
45
46
# File 'lib/santey_vote/voteable.rb', line 44

def votes_count
  self.votes.size
end

#votes_forObject



27
28
29
30
31
32
33
# File 'lib/santey_vote/voteable.rb', line 27

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