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
- #extend_env(obj, msg) ⇒ Object
-
#initialize(pat = nil) ⇒ TextMatcher
constructor
A new instance of TextMatcher.
Methods inherited from Matcher
Constructor Details
#initialize(pat = nil) ⇒ TextMatcher
Returns a new instance of TextMatcher.
23 24 25 |
# File 'lib/telegram_bot/matcher.rb', line 23 def initialize(pat = nil) @pattern = pat end |
Instance Attribute Details
#pattern ⇒ Object
Returns the value of attribute pattern.
21 22 23 |
# File 'lib/telegram_bot/matcher.rb', line 21 def pattern @pattern end |
Instance Method Details
#===(msg) ⇒ Object
27 28 29 30 31 |
# File 'lib/telegram_bot/matcher.rb', line 27 def ===(msg) return false unless msg.type == :text return true if @pattern.nil? @pattern === msg.text end |
#arguments(msg) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/telegram_bot/matcher.rb', line 49 def arguments(msg) if Regexp === @pattern md = @pattern.match(msg.text) md.to_a else [msg.text] end end |
#extend_env(obj, msg) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/telegram_bot/matcher.rb', line 33 def extend_env(obj, msg) obj = super if Regexp === @pattern md = @pattern.match(msg.text) obj.extend do md.names.each do |grp| value = md[grp] define_method grp { value } end end end obj end |