Class: TelegramBot::TextMatcher
- Defined in:
- lib/telegram_bot/matcher.rb
Instance Attribute Summary collapse
-
#pattern ⇒ Object
Returns the value of attribute pattern.
Instance Method Summary collapse
- #===(msg) ⇒ Object
- #arguments(msg) ⇒ Object
-
#initialize(pat = nil) ⇒ TextMatcher
constructor
A new instance of TextMatcher.
Constructor Details
#initialize(pat = nil) ⇒ TextMatcher
Returns a new instance of TextMatcher.
15 16 17 |
# File 'lib/telegram_bot/matcher.rb', line 15 def initialize(pat = nil) @pattern = pat end |
Instance Attribute Details
#pattern ⇒ Object
Returns the value of attribute pattern.
13 14 15 |
# File 'lib/telegram_bot/matcher.rb', line 13 def pattern @pattern end |
Instance Method Details
#===(msg) ⇒ Object
19 20 21 22 23 |
# File 'lib/telegram_bot/matcher.rb', line 19 def ===(msg) return false unless msg.type == :text return true if @pattern.nil? @pattern === msg.text end |
#arguments(msg) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/telegram_bot/matcher.rb', line 25 def arguments(msg) if Regexp === @pattern md = @pattern.match(msg.text) md.to_a else [msg.text] end end |