Class: Sinbotra::MessageHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/sinbotra/message_handler.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(provider, async = true) ⇒ MessageHandler

Returns a new instance of MessageHandler.



13
14
15
16
# File 'lib/sinbotra/message_handler.rb', line 13

def initialize(provider, async=true)
  @provider = provider
  @is_async = async
end

Class Attribute Details

.handlersObject (readonly)

Returns the value of attribute handlers.



3
4
5
# File 'lib/sinbotra/message_handler.rb', line 3

def handlers
  @handlers
end

Instance Attribute Details

#providerObject (readonly)

Returns the value of attribute provider.



11
12
13
# File 'lib/sinbotra/message_handler.rb', line 11

def provider
  @provider
end

Class Method Details

.add_handler(provider, handler) ⇒ Object



5
6
7
8
# File 'lib/sinbotra/message_handler.rb', line 5

def add_handler(provider, handler)
  @handlers ||= {}
  @handlers[provider] = handler
end

Instance Method Details

#handler_classObject



25
# File 'lib/sinbotra/message_handler.rb', line 25

def handler_class; self.class.handlers[@provider]; end

#receive_messages(messages) ⇒ Object



18
19
20
21
22
23
# File 'lib/sinbotra/message_handler.rb', line 18

def receive_messages(messages)
  messages.each do |msg|
    bot = handler_class.new(msg)
    bot.respond
  end
end