Sha256: 0f3f48290ec57eb3d1c92ac2139eeab93ff7b13fa70b7e5989be3ee5af30ae1a
Contents?: true
Size: 683 Bytes
Versions: 1
Compression:
Stored size: 683 Bytes
Contents
module Cognition class Matcher attr_accessor :trigger, :action, :response, :help def initialize(trigger, help = 'Undocumented', &action) raise ArgumentError, 'matcher must have a trigger' unless trigger raise ArgumentError, 'matcher must have a action' unless action @trigger = trigger @help = help @action = action end def attempt(msg) return false unless matches?(msg) run(msg) end def run(msg) @response = action.call(msg) end def matches?(msg) case trigger when String trigger == msg.command when Regexp trigger.match msg.command end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
cognition-1.0.1 | lib/cognition/matcher.rb |