Class: TelegramMeetupBot::ParamsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/telegram_meetup_bot/params_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg) ⇒ ParamsParser

Returns a new instance of ParamsParser.



8
9
10
# File 'lib/telegram_meetup_bot/params_parser.rb', line 8

def initialize(arg)
  @arg = arg
end

Instance Attribute Details

#argObject (readonly)

Returns the value of attribute arg.



6
7
8
# File 'lib/telegram_meetup_bot/params_parser.rb', line 6

def arg
  @arg
end

Instance Method Details

#parse_dateObject



12
13
14
15
16
17
18
19
20
21
22
23
# 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_monthObject



31
32
33
34
35
36
37
# 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_timeObject



25
26
27
28
29
# 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