Class: Toast::Responder

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel, from) ⇒ Responder



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

def initialize channel, from
  @channel=channel
  @from=from
end

Instance Attribute Details

#fromObject

Returns the value of attribute from.



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

def from
  @from
end

Instance Method Details

#handle(msg) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/responder.rb', line 10

def handle msg
  callcc do |back_to_channel|
    @back_to_channel = back_to_channel
    
    if @leftoff
      @leftoff.call(msg)
    else
      response=respond(msg)
      say response unless response.nil?
      @leftoff=nil
      @back_to_channel.call
    end
  end
end

#respond(msg) ⇒ Object

Override me to handle messages!



26
27
28
29
# File 'lib/responder.rb', line 26

def respond msg
  say "Override #{self.class.name}.respond to have your bot do something."
  nil
end

#say(msg) ⇒ Object



38
39
40
41
# File 'lib/responder.rb', line 38

def say msg
  @channel.send msg, @from
  nil
end

#waitObject



31
32
33
34
35
36
# File 'lib/responder.rb', line 31

def wait
  callcc do |cc|
    @leftoff=cc
    @back_to_channel.call
  end
end