Class: Scamp::Matcher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bot, params = {}) ⇒ Matcher

Returns a new instance of Matcher.



5
6
7
8
9
10
# File 'lib/scamp/matcher.rb', line 5

def initialize(bot, params = {})
  params ||= {}
  params[:conditions] ||= {}
  params.each { |k,v| send("#{k}=", v) }
  @bot = bot
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



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

def action
  @action
end

#botObject

Returns the value of attribute bot.



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

def bot
  @bot
end

#conditionsObject

Returns the value of attribute conditions.



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

def conditions
  @conditions
end

#required_prefixObject

Returns the value of attribute required_prefix.



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

def required_prefix
  @required_prefix
end

#triggerObject

Returns the value of attribute trigger.



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

def trigger
  @trigger
end

Instance Method Details

#attempt(msg) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/scamp/matcher.rb', line 12

def attempt(msg)
  return false unless conditions_satisfied_by(msg)
  match = triggered_by(msg[:body])
  if match
    if match.is_a? MatchData
      run(msg, match)
    else
      run(msg)
    end
    return true
  end
  false
end