Class: Roflbot::Base::Expectation

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

Instance Method Summary collapse

Constructor Details

#initialize(regexp) ⇒ Expectation

Returns a new instance of Expectation.



4
5
6
# File 'lib/roflbot/base.rb', line 4

def initialize(regexp)
  @regexp = regexp
end

Instance Method Details

#matches?(message) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/roflbot/base.rb', line 8

def matches?(message)
  @regexp =~ message
end

#responds(message = nil, &block) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/roflbot/base.rb', line 12

def responds(message = nil, &block)
  if block_given?
    @response = block
  else
    @response = message
  end
end

#responseObject



20
21
22
23
24
25
26
27
# File 'lib/roflbot/base.rb', line 20

def response
  case @response
  when String
    @response
  when Proc
    @response.call
  end
end