Permalink
Browse files

Initial Commit - regex for question matching

  • Loading branch information...
0 parents commit 047fd03d3db8bc671de2ca1ab2f24fad4690222f @burtlo committed Oct 14, 2011
Showing with 91 additions and 0 deletions.
  1. +9 −0 Gemfile
  2. +8 −0 Guardfile
  3. +45 −0 lib/quiz.rb
  4. +28 −0 spec/quiz_spec.rb
  5. +1 −0 spec/spec_helper.rb
@@ -0,0 +1,9 @@
+source :rubygems
+
+gem 'robut'
+
+group :test do
+ gem 'rspec'
+ gem 'guard'
+ gem 'guard-rspec'
+end
@@ -0,0 +1,8 @@
+
+
+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('spec/spec_helper.rb') { "spec" }
+end
+
@@ -0,0 +1,45 @@
+# encoding: UTF-8
+require 'robut'
+
+class Robut::Plugin::Quiz
+ include Robut::Plugin
+
+ # @see http://rubular.com?regex=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*)*(%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?)?$/
+
+ def usage
+ [
+ "#{at_nick} ask choice (question) 'What do you want for lunch?', 'pizza', 'sandwich', 'salad' for 1 minute",
+ "#{at_nick} ask polar (question) 'Should I continue the presentation?' for 3 minutes",
+ "#{at_nick} ask scale (question) 'how much did you like the presentation?', '1..5'",
+ "#{at_nick} ask 'Should I continue the presentation?', 'y|yes', 'n|no' for 1 minutes"
+ ]
+ end
+
+ def handle(time, sender_nick, message)
+
+ # check to see if the user is asking the bot a question
+
+ if sent_to_me? message and is_a_question? message
+
+
+
+
+ end
+
+ # check to see what time of question the user is asking
+
+ # allow each question to handle the question appropriately for the default
+
+ end
+
+ def is_a_valid_question? message
+ message =~ QUESTION_REGEX
+ end
+
+end
@@ -0,0 +1,28 @@
+require_relative 'spec_helper'
+
+describe Robut::Plugin::Quiz do
+
+ subject {
+ connection = double("connection")
+ connection.stub_chain(:config, :nick) { "quizmaster" }
+ Robut::Plugin::Quiz.new connection
+ }
+
+
+ [
+ "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'",
+ "ask 'Should I continue the presentation?', 'y|yes', 'n|no' for 1 minutes"
+
+ ].each do |question|
+
+ it "should match the question: '#{question}'" do
+
+ subject.is_a_valid_question?(question).should be_true
+
+ end
+
+ end
+
+end
@@ -0,0 +1 @@
+require_relative '../lib/quiz'

0 comments on commit 047fd03

Please sign in to comment.