Permalink
Browse files

Question: Format Change

  * Changed to move the time component to be at the front of the question
  * Changed to make the time component optional; defaults to 2 minutes
  • Loading branch information...
1 parent b9e7559 commit ad7a7b7dce7d7da58d00634b10fdfcd2a246bbbb @burtlo committed Oct 26, 2011
Showing with 23 additions and 29 deletions.
  1. +0 −4 lib/polar.rb
  2. +8 −11 lib/question.rb
  3. +5 −4 lib/quiz.rb
  4. +1 −1 spec/polar_spec.rb
  5. +9 −9 spec/quiz_spec.rb
View
4 lib/polar.rb
@@ -32,10 +32,6 @@ def results
"#{yes_votes} YES vote#{yes_votes != 1 ? 's' : ''} and #{no_votes} NO vote#{no_votes != 1 ? 's' : ''}"
end
- def captured_results
- @captured_results ||= {}
- end
-
def store_positive_response_for sender_nick
captured_results[sender_nick] = true
end
View
19 lib/question.rb
@@ -2,14 +2,6 @@
module Robut::Plugin::Quiz::Question
- # @see ask%20%3F(choice%7Cpolar%7Cscale)%3F%20(%3F%3Aquestion%20)%3F'(%5B%5E'%5D%2B)'%5B%5Cs%2C%5D*((%3F%3A'%5B%5E'%5D%2B'%5B%5Cs%2C%5D*)*)%2B(%3F%3A(%3F%3Afor%20)%3F(%5Cd%2B)%20minutes%3F)%3F
- #
- # 1st: question type - choice, polar, scale
- # 2nd: question
- # 3rd: choices
- #
- QUESTION_REGEX = /^ask ?(choice|polar|scale)? (?:question )?['"]([^'"]+)['"][\s,]*((?:['"][^'"]+['"][\s,]*)*)*(?:(?:for )?(\d+) minutes?)?$/
-
# This regex will find all the questions and parameters specified with the question
GROUP_REGEX = /['"]([^'"]+)['"]/
@@ -20,11 +12,12 @@ def initialize(sender,request)
def process_question(request)
- request =~ QUESTION_REGEX
- @question = Regexp.last_match(2)
+ parsed_parameters = request.scan(GROUP_REGEX)
+
+ @question = parsed_parameters.first
# After the target, question type, question, and answer length has been determined
# look at all the single quoted items to find the list of parameters if there are any
- @parameters = request.scan(GROUP_REGEX)[1..-1].flatten
+ @parameters = parsed_parameters[1..-1].flatten
end
@@ -36,4 +29,8 @@ def ask
"@all Question '#{@question}'"
end
+ def captured_results
+ @captured_results ||= {}
+ end
+
end
View
9 lib/quiz.rb
@@ -5,7 +5,7 @@ class Robut::Plugin::Quiz
include Robut::Plugin
def usage
- [
+ [ "#{at_nick} ask 'Should we break for lunch?'",
"#{at_nick} ask polar 'Should I continue the presentation?' for 3 minutes",
]
end
@@ -29,7 +29,7 @@ def handle(time, sender_nick, message)
end
- QUESTION_REGEX = /^ask ?(choice|polar|scale)? (?:question )?.+(?:(?:for )?(\d+) minutes?)$/
+ QUESTION_REGEX = /^ask ?(choice|polar|scale)? (?:question )?(?:(?:for )?(\d+) minutes?)?(.+)$/
def is_a_valid_question? message
QUESTION_REGEX =~ message
@@ -67,9 +67,10 @@ def process_the_question(sender,request)
request =~ QUESTION_REGEX
type = Regexp.last_match(1) || 'polar'
- question_length = Regexp.last_match(2) || '2'
+ question_length = Regexp.last_match(2) || '2'
+ question_data = Regexp.last_match(3)
- set_current_question create_the_question_based_on_type(type,sender,request), question_length
+ set_current_question create_the_question_based_on_type(type,sender,question_data), question_length
end
#
View
2 spec/polar_spec.rb
@@ -3,7 +3,7 @@
describe Robut::Plugin::Quiz::Polar do
subject do
- Robut::Plugin::Quiz::Polar.new 'person',"ask polar 'Should I continue the presentation?' for 3 minutes"
+ Robut::Plugin::Quiz::Polar.new 'person',"'Should I continue the presentation?'"
end
let(:time) { Time.now }
View
18 spec/quiz_spec.rb
@@ -15,11 +15,11 @@
let(:time) { Time.now }
[
- "ask choice 'What do you want for lunch?', 'pizza', 'sandwich', 'salad' for 1 minute",
- "ask polar 'Should I continue the presentation?' for 3 minutes",
- "ask scale question 'how much did you like the presentation?', '1..5' for 10 minutes",
- "ask 'Should I continue the presentation?', 'y|yes', 'n|no' for 1 minutes",
- "ask polar 'Should I continue the presentation?' for 3 minutes"
+ "ask 'Should I continue the presentation?'",
+ "ask for 3 minutes 'Should I continue the presentation?'",
+ "ask polar for 3 minutes 'Should I continue the presentation?'",
+ "ask choice 1 minute 'What do you want for lunch?', 'pizza', 'sandwich', 'salad'",
+ "ask scale question for 10 minutes 'how much did you like the presentation?', '1..5'"
].each do |question|
@@ -55,7 +55,7 @@
subject.should_not_receive(:process_response_for_active_question)
- subject.handle time,'person',"@quizmaster ask polar 'Should I continue the presentation?' for 3 minutes"
+ subject.handle time,'person',"@quizmaster ask polar for 3 minutes 'Should I continue the presentation?'"
end
@@ -70,7 +70,7 @@
subject.should_receive(:process_response_for_active_question)
- subject.handle time,'person',"@quizmaster ask polar 'Should I continue the presentation?' for 3 minutes"
+ subject.handle time,'person',"@quizmaster ask polar for 3 minutes 'Should I continue the presentation?'"
end
@@ -93,7 +93,7 @@
subject.should_receive(:create_the_question_based_on_type).and_return(expected_question)
subject.should_receive(:set_current_question).with(expected_question,'3')
- subject.process_the_question 'person',"ask polar 'Should I continue the presentation?' for 3 minutes"
+ subject.process_the_question 'person',"ask polar for 3 minutes 'Should I continue the presentation?'"
end
@@ -109,7 +109,7 @@
end
let(:question) do
- Robut::Plugin::Quiz::Polar.new 'person',"ask polar 'Should I continue the presentation?' for 3 minutes"
+ Robut::Plugin::Quiz::Polar.new 'person',"'Should I continue the presentation?'"
end
it "should place robut in the mode where it is asking a question" do

0 comments on commit ad7a7b7

Please sign in to comment.