Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Some basic question logic in place

  • Loading branch information...
commit b0723c3fa699bb425b2b4bca612cad69ec26ab7d 1 parent 047fd03
@burtlo authored
Showing with 60 additions and 3 deletions.
  1. +1 −0  Gemfile
  2. +1 −1  Guardfile
  3. +32 −2 lib/quiz.rb
  4. +26 −0 spec/quiz_spec.rb
View
1  Gemfile
@@ -6,4 +6,5 @@ group :test do
gem 'rspec'
gem 'guard'
gem 'guard-rspec'
+ gem 'growl_notify'
end
View
2  Guardfile
@@ -2,7 +2,7 @@
guard 'rspec', :version => 2, :cli => '--color --format d' do
watch(%r{^spec/.+_spec\.rb$})
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
end
View
34 lib/quiz.rb
@@ -24,10 +24,28 @@ def usage
def handle(time, sender_nick, message)
# check to see if the user is asking the bot a question
+ request = words(message).join(" ")
- if sent_to_me? message and is_a_question? message
+ if sent_to_me? message and is_a_valid_question? request
+ request =~ QUESTION_REGEX
+ question_type = Regexp.last_match(1) || 'choice'
+ question = Regexp.last_match(2)
+ parameters = Regexp.last_match(3)
+ answer_length = Regexp.last_match(4) || '2'
+ puts %{ #{question_type} }
+
+ case question_type
+ when 'polar'
+ handle_polar(question,parameters,answer_length)
+ when 'choice'
+ handle_choice(question,parameters,answer_length)
+ when 'scale'
+ handle_scale(question,parameters,answer_length)
+ else
+ puts "failed to find a question type"
+ end
end
@@ -38,8 +56,20 @@ def handle(time, sender_nick, message)
end
+ def handle_polar(question,parameters,length)
+ puts "#{question} #{parameters} #{length}"
+ end
+
+ def handle_choice(question,parameters,length)
+ puts "#{question} #{parameters} #{length}"
+ end
+
+ def handle_scale(question,parameters,length)
+ puts "#{question} #{parameters} #{length}"
+ end
+
def is_a_valid_question? message
- message =~ QUESTION_REGEX
+ QUESTION_REGEX =~ message
end
end
View
26 spec/quiz_spec.rb
@@ -24,5 +24,31 @@
end
end
+
+ describe "#handle" do
+
+ context "when a polar question is asked" do
+
+ it "should find all the components of the question" do
+
+ subject.should_receive(:handle_polar).with('Should I continue the presentation?',nil,'3')
+ subject.handle Time.now,'person',"@quizmaster ask polar 'Should I continue the presentation?' for 3 minutes"
+
+ end
+
+ end
+
+ context "when a choice question is asked" do
+
+ it "should find all the components of the question" do
+
+ subject.should_receive(:handle_choice).with('What should I talk about next?',"'x', 'y', 'z'",'2')
+ subject.handle Time.now,'person',"@quizmaster ask choice 'What should I talk about next?', 'x', 'y', 'z'"
+
+ end
+
+ end
+
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.