Class: ActsAsCaesar::Voter

Inherits:
Object
  • Object
show all
Defined in:
lib/acts_as_caesar/objects/voter.rb

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Voter

Returns a new instance of Voter.



6
7
8
# File 'lib/acts_as_caesar/objects/voter.rb', line 6

def initialize(source)
  @source = source || NoVoter.new
end

Instance Method Details

#has_voted_on?(candidate) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/acts_as_caesar/objects/voter.rb', line 10

def has_voted_on?(candidate)
  !vote_placed_on(candidate).kind_of?(NoVote)
end

#keyObject



26
27
28
# File 'lib/acts_as_caesar/objects/voter.rb', line 26

def key
  Key.for_source(source)
end

#to_json(*args) ⇒ Object



30
31
32
# File 'lib/acts_as_caesar/objects/voter.rb', line 30

def to_json(*args)
  key
end

#update_vote(candidate, value) ⇒ Object



18
19
20
# File 'lib/acts_as_caesar/objects/voter.rb', line 18

def update_vote(candidate, value)
  vote_placed_on(candidate).update(value)
end

#vote_placed_on(candidate) ⇒ Object



22
23
24
# File 'lib/acts_as_caesar/objects/voter.rb', line 22

def vote_placed_on(candidate)
  Vote.find(voter: self, candidate: candidate)
end

#vote_value_for(candidate) ⇒ Object



14
15
16
# File 'lib/acts_as_caesar/objects/voter.rb', line 14

def vote_value_for(candidate)
  vote_placed_on(candidate).value
end