class Tadpoll::Option
Public Class Methods
new_option(name, poll_id)
click to toggle source
Create Option
# File lib/tadpoll/option.rb, line 9 def self.new_option(name, poll_id) return false if name.blank? option = Tadpoll::Option.new(name: name, poll_id: poll_id) if option.save return option else return false end end
Public Instance Methods
find_votes_for(voter)
click to toggle source
Votes with given parameters
# File lib/tadpoll/option.rb, line 54 def find_votes_for(voter) votes.where(voter_id: voter.id) end
unvote(voter)
click to toggle source
Destory Votes with given parameters
# File lib/tadpoll/option.rb, line 44 def unvote(voter) return false if voter.nil? if self.voted_on_by?(voter) _votes_ = find_votes_for(voter) _votes_.each(&:destroy) end return true end
vote(voter)
click to toggle source
# File lib/tadpoll/option.rb, line 22 def vote(voter) return false if voter.nil? if self.poll.voted_on_by?(voter) return false else vote = Tadpoll::Vote.new( option: self, voter_id: voter.id, voter_type: voter.class.base_class.name, poll_id: self.poll_id ) end if vote.save return true else return false end end
vote_count()
click to toggle source
Count of Votes for an Option
# File lib/tadpoll/option.rb, line 59 def vote_count votes.count end
voted_on?()
click to toggle source
T / F Has the Option
been voted on
# File lib/tadpoll/option.rb, line 64 def voted_on? votes.count > 0 end