= Message Router Message router is a Sinatra-like DSL for processing simple messages, like SMS messages or Tweets. == Installation sudo gem install message_router == Example Code This is a contrived example for a Twitter message router, but it gives you an idea of how it works. class TwitterRouter < MessageRouter context :all_caps_with_numbers do # All caps without numbers... but in a proc context Proc.new{|r| r.message[:body] =~ /^[A-Z\s]+$/ } do match /.+/ do "STOP SHOUTING WITHOUT NUMBERS!" end end match /.+/ do "STOP SHOUTING WITH NUMBERS!" end end match /hi dude/ do "pleased to meet you" end match /hi (\w+)/ do |name| "how do you do #{name}" end match /hola (\w+)/, :from => 'bradgessler' do |name| "hello #{name} in spanish" end private def all_caps_with_numbers message[:body] =~ /^[A-Z0-9\s]+$/ end end And now some irb action. >> TwitterRouter.new(:body => 'hi dude').dispatch => {:body => "pleased to meet you"} >> TwitterRouter.new(:body => 'hi brad').dispatch => {:body => "how do you do brad"} >> TwitterRouter.new(:body => 'HI BRAD 90').dispatch => {:body => "STOP SHOUTING WITH NUMBERS!"} >> TwitterRouter.new(:body => 'HI BRAD').dispatch => {:body => "STOP SHOUTING WITHOUT NUMBERS!"} == License Copyright (c) 2010, Brad Gessler Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.