Class: TelegramBot::TextMatcher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#patternObject

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