Class: Robut::Plugin::Quiz::Polar

Inherits:
Object
  • Object
show all
Includes:
Question
Defined in:
lib/polar.rb

Constant Summary collapse

YES_ANSWER =
/y|yes/i
NO_ANSWER =
/n|no/i

Instance Method Summary collapse

Instance Method Details

#askObject



35
36
37
# File 'lib/polar.rb', line 35

def ask
  "@all Question '#{@question}' (yes/no)"
end

#handle_response(sender_nick, response) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/polar.rb', line 9

def handle_response(sender_nick,response)
  
  if response =~ YES_ANSWER
    store_positive_response_for sender_nick
    true
  elsif response =~ NO_ANSWER
    store_negative_response_for sender_nick
    true
  else
    nil
  end
  
end

#resultsObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/polar.rb', line 23

def results
  
  yes_votes = no_votes = 0
  
  captured_results.each_pair do |key,value|
    yes_votes = yes_votes + 1 if value
    no_votes = no_votes + 1 unless value
  end
  
  "#{yes_votes} YES vote#{yes_votes != 1 ? 's' : ''} and #{no_votes} NO vote#{no_votes != 1 ? 's' : ''}"
end

#store_negative_response_for(sender_nick) ⇒ Object



43
44
45
# File 'lib/polar.rb', line 43

def store_negative_response_for sender_nick
  captured_results[sender_nick] = false
end

#store_positive_response_for(sender_nick) ⇒ Object



39
40
41
# File 'lib/polar.rb', line 39

def store_positive_response_for sender_nick
  captured_results[sender_nick] = true
end