Class: Robut::Plugin::Quiz::Range
- Inherits:
-
Object
- Object
- Robut::Plugin::Quiz::Range
- Includes:
- Question
- Defined in:
- lib/range.rb
Defined Under Namespace
Modules: Averages
Constant Summary collapse
- RANGE_VALUES =
/(\d+)(?:-|\.\.)(\d+)/
Instance Method Summary collapse
- #ask ⇒ Object
- #handle_response(sender_nick, response) ⇒ Object
- #highest_value ⇒ Object
- #results ⇒ Object
- #start_value ⇒ Object
- #store_range_response_for(sender_nick, value) ⇒ Object
- #within_range?(value) ⇒ Boolean
Instance Method Details
#ask ⇒ Object
39 40 41 |
# File 'lib/range.rb', line 39 def ask "@all Question '#{@question}' (#{start_value}..#{highest_value})" end |
#handle_response(sender_nick, response) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/range.rb', line 8 def handle_response(sender_nick,response) if within_range? response store_range_response_for sender_nick, response true else false end end |
#highest_value ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/range.rb', line 27 def highest_value if Array(@parameters).first.to_s =~ RANGE_VALUES Regexp.last_match(2).to_i else 5 end end |
#results ⇒ Object
43 44 45 46 47 48 |
# File 'lib/range.rb', line 43 def results return "I'm sorry, not enough votes were cast to be create a summary." if captured_results.length == 0 result_values = captured_results.values.extend Robut::Plugin::Quiz::Range::Averages "#{result_values.length} votes with a mean of #{result_values.mean}" end |
#start_value ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/range.rb', line 19 def start_value if Array(@parameters).first.to_s =~ RANGE_VALUES Regexp.last_match(1).to_i else 1 end end |
#store_range_response_for(sender_nick, value) ⇒ Object
50 51 52 |
# File 'lib/range.rb', line 50 def store_range_response_for(sender_nick,value) captured_results[sender_nick] = value.to_i end |
#within_range?(value) ⇒ Boolean
35 36 37 |
# File 'lib/range.rb', line 35 def within_range?(value) value.to_i >= start_value and value.to_i <= highest_value end |