Class: ActsAsCaesar::Voter
- Inherits:
-
Object
- Object
- ActsAsCaesar::Voter
- Defined in:
- lib/acts_as_caesar/objects/voter.rb
Instance Method Summary collapse
- #has_voted_on?(candidate) ⇒ Boolean
-
#initialize(source) ⇒ Voter
constructor
A new instance of Voter.
- #key ⇒ Object
- #to_json(*args) ⇒ Object
- #update_vote(candidate, value) ⇒ Object
- #vote_placed_on(candidate) ⇒ Object
- #vote_value_for(candidate) ⇒ Object
Constructor Details
Instance Method Details
#has_voted_on?(candidate) ⇒ 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 |
#key ⇒ Object
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 |