class TelegramBot::CommandMatcher

Attributes

command[RW]

Public Class Methods

new(command = nil, no_split: false) click to toggle source
# File lib/telegram_bot/matcher.rb, line 38
def initialize(command = nil, no_split: false)
  @command = command
  @no_split = no_split
end

Public Instance Methods

===(msg) click to toggle source
# File lib/telegram_bot/matcher.rb, line 43
def ===(msg)
  start_with = '/'
  if !@command.nil?
    start_with += @command.to_s
  end
  return false if msg.type != :text
  return false if !msg.text.start_with? start_with

  true
end
arguments(msg) click to toggle source
# File lib/telegram_bot/matcher.rb, line 54
def arguments(msg)
  case
  when @no_split
    cmd, _, args = msg.text.parition(/\s/)
    [cmd[1..-1], args]
  when @comamnd.nil?
    cmd, *args = msg.text.split
    [cmd[1..-1], *args]
  else
    cmd, *args = msg.text.split
    args
  end
end