Class: SlackBot::MatcherGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/slack/matchers/matcher_group.rb

Instance Method Summary collapse

Constructor Details

#initialize(action) ⇒ MatcherGroup

Returns a new instance of MatcherGroup.



5
6
7
8
# File 'lib/slack/matchers/matcher_group.rb', line 5

def initialize(action)
  @action = action
  @matchers = []
end

Instance Method Details

#before_match(&block) ⇒ Object



23
24
25
# File 'lib/slack/matchers/matcher_group.rb', line 23

def before_match(&block)
  @before_match = block
end

#respond_for(msg) ⇒ Object



10
11
12
13
14
15
# File 'lib/slack/matchers/matcher_group.rb', line 10

def respond_for(msg)
  @before_match.call(msg) if @before_match
  @matchers.each do |m|
    break if m.run_on(msg)
  end
end

#to_sObject



27
28
29
# File 'lib/slack/matchers/matcher_group.rb', line 27

def to_s
  "#{@action} #{@matchers.count}"
end

#whenObject



17
18
19
20
21
# File 'lib/slack/matchers/matcher_group.rb', line 17

def when
  m = Matcher.new
  @matchers.push m
  return m
end