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, for_or_against = "all") ⇒ Boolean

Returns:

  • (Boolean)


150
151
152
153
# File 'lib/acts_as_voteable.rb', line 150

def voted_by?(voter, for_or_against = "all")
  options = (for_or_against == "all") ? {} : {:vote => (for_or_against ? 1 : -1)}
  self.votes.exists?({:voter_id => voter.id, :voter_type => voter.class.name}.merge(options))
end

#voters_who_votedObject



146
147
148
# File 'lib/acts_as_voteable.rb', line 146

def voters_who_voted
  self.votes.collect(&:voter)
end

#votes_againstObject



133
134
135
# File 'lib/acts_as_voteable.rb', line 133

def votes_against
  self.votes.count(:conditions => {:vote => -1})
end

#votes_countObject

Same as voteable.votes.size



138
139
140
# File 'lib/acts_as_voteable.rb', line 138

def votes_count
  self.votes.size
end

#votes_forObject



129
130
131
# File 'lib/acts_as_voteable.rb', line 129

def votes_for
  self.votes.count(:conditions => {:vote => 1})
end

#votes_totalObject



142
143
144
# File 'lib/acts_as_voteable.rb', line 142

def votes_total
  respond_to?(:vote_counter_column) ? send(self.vote_counter_column) : self.votes.sum(:vote)
end