module Tools::Votable

Métodos compartidos entre todas las clases que se pueden votar Ahora: Debate y Propuesta

Public Instance Methods

n_against() click to toggle source
# File app/models/tools/votable.rb, line 50
def n_against
  @against ||= self.votes.count('value', :conditions => "value = -1")
end
n_in_favor() click to toggle source
# File app/models/tools/votable.rb, line 46
def n_in_favor
  @in_favor ||= self.votes.count('value', :conditions => "value = 1")
end
participation() click to toggle source
# File app/models/tools/votable.rb, line 42
def participation
  self.n_in_favor + self.n_against
end
percent_against() click to toggle source
# File app/models/tools/votable.rb, line 30
def percent_against
  100 - percent_in_favor
end
percent_in_favor() click to toggle source
# File app/models/tools/votable.rb, line 25
def percent_in_favor
  return 0 if participation == 0
  (self.n_in_favor * 100.00 / participation).round
end
percent_neutral() click to toggle source
# File app/models/tools/votable.rb, line 34
def percent_neutral
  50
end
percentage() click to toggle source
# File app/models/tools/votable.rb, line 38
def percentage
  [percent_in_favor, percent_against].sort.last
end
percentage_to_text() click to toggle source
# File app/models/tools/votable.rb, line 54
def percentage_to_text
  if self.percent_in_favor == 50 || self.participation == 0
    "neutral"
  elsif self.percent_in_favor > self.percent_against
    "in_favor"
  else
    "against"
  end
end