Class: Robut::Plugin::Quiz::Range

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

Defined Under Namespace

Modules: Averages

Constant Summary collapse

RANGE_VALUES =
/(\d+)(?:-|\.\.)(\d+)/

Instance Method Summary collapse

Instance Method Details

#askObject



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_valueObject



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

#resultsObject



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_valueObject



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

Returns:

  • (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