Class: Scamp::Matcher
- Inherits:
-
Object
- Object
- Scamp::Matcher
- Defined in:
- lib/scamp/matcher.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#bot ⇒ Object
Returns the value of attribute bot.
-
#conditions ⇒ Object
Returns the value of attribute conditions.
-
#required_prefix ⇒ Object
Returns the value of attribute required_prefix.
-
#trigger ⇒ Object
Returns the value of attribute trigger.
Instance Method Summary collapse
- #attempt(msg) ⇒ Object
-
#initialize(bot, params = {}) ⇒ Matcher
constructor
A new instance of Matcher.
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
#action ⇒ Object
Returns the value of attribute action.
3 4 5 |
# File 'lib/scamp/matcher.rb', line 3 def action @action end |
#bot ⇒ Object
Returns the value of attribute bot.
3 4 5 |
# File 'lib/scamp/matcher.rb', line 3 def bot @bot end |
#conditions ⇒ Object
Returns the value of attribute conditions.
3 4 5 |
# File 'lib/scamp/matcher.rb', line 3 def conditions @conditions end |
#required_prefix ⇒ Object
Returns the value of attribute required_prefix.
3 4 5 |
# File 'lib/scamp/matcher.rb', line 3 def required_prefix @required_prefix end |
#trigger ⇒ Object
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 |