class TelegramMeetupBot::ParamsParser

Attributes

arg[R]

Public Class Methods

new(arg) click to toggle source
# File lib/telegram_meetup_bot/params_parser.rb, line 8
def initialize(arg)
  @arg = arg
end

Public Instance Methods

parse_date() click to toggle source
# File lib/telegram_meetup_bot/params_parser.rb, line 12
def parse_date
  format = case arg
  when /\A[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{2}\Z/
    "%d.%m.%y"
  when /\A[0-9]{1,2}\.[0-9]{1,2}\Z/
    "%d.%m"
  when /\A[0-9]{1,2}\Z/
    "%d"
  end

  Date.strptime(arg, format) rescue nil
end
parse_month() click to toggle source
# File lib/telegram_meetup_bot/params_parser.rb, line 31
def parse_month
  month = arg.to_i

  if month >= 1 && month <= 12
    month
  end
end
parse_time() click to toggle source
# File lib/telegram_meetup_bot/params_parser.rb, line 25
def parse_time
  if arg =~ /\A[0-2][0-9]:[0-5][0-9]\Z/
    Time.parse(arg).strftime('%R') rescue nil
  end
end