Sha256: 2ba9f7a0a9213c8731107e2330e2af6ca0c7067bc0e716bffffdccb0a8265dcc

Contents?: true

Size: 601 Bytes

Versions: 9

Compression:

Stored size: 601 Bytes

Contents

module MadChatter
  module Actions
    class Base
    
      include MadChatter::Actions::Dsl
    
      def initialize(regex = nil, block = nil)
        @regex = regex
        @block = block
      end
    
      def handle(message)
        if message.original_text =~ @regex
          args = @regex.match(message.original_text).captures
          @block.call(args)
        end
      end
    
      # used to register a class that extends MadChatter::Actions::Base
      def self.inherited(extension_class)
        MadChatter.message_listeners << extension_class.new
      end
      
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
mad_chatter-0.3.1 lib/mad_chatter/actions/base.rb
mad_chatter-0.3.0 lib/mad_chatter/actions/base.rb
mad_chatter-0.2.9 lib/mad_chatter/actions/base.rb
mad_chatter-0.2.8 lib/mad_chatter/actions/base.rb
mad_chatter-0.2.7 lib/mad_chatter/actions/base.rb
mad_chatter-0.2.6 lib/mad_chatter/actions/base.rb
mad_chatter-0.2.5 lib/mad_chatter/actions/base.rb
mad_chatter-0.2.4 lib/mad_chatter/actions/base.rb
mad_chatter-0.2.3 lib/mad_chatter/actions/base.rb