Class: Robut::Plugin::Quiz::Choice
- Inherits:
-
Object
- Object
- Robut::Plugin::Quiz::Choice
- Includes:
- Question
- Defined in:
- lib/choice.rb
Instance Method Summary collapse
- #a_valid_choice(response) ⇒ Object
- #ask ⇒ Object
- #handle_response(sender_nick, response) ⇒ Object
- #results ⇒ Object
- #store_response(sender_nick, response) ⇒ Object
Instance Method Details
#a_valid_choice(response) ⇒ Object
21 22 23 |
# File 'lib/choice.rb', line 21 def a_valid_choice(response) @parameters.find {|choice| choice == response } end |
#ask ⇒ Object
6 7 8 |
# File 'lib/choice.rb', line 6 def ask "@all Question '#{@question}' #{@parameters.map {|p| "'#{p}'" }.join(", ")})" end |
#handle_response(sender_nick, response) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/choice.rb', line 10 def handle_response(sender_nick,response) if a_valid_choice response store_response sender_nick, response true else false end end |
#results ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/choice.rb', line 29 def results response = @parameters.map do |choice| found = captured_results.values.find_all {|result| result == choice } "#{found.length} '#{choice}'" unless found.empty? end.compact.join(", ") response.empty? ? "No votes have been made" : response end |
#store_response(sender_nick, response) ⇒ Object
25 26 27 |
# File 'lib/choice.rb', line 25 def store_response(sender_nick,response) captured_results[sender_nick] = response end |