Class: TelegramMeetupBot::ParamsParser
- Inherits:
-
Object
- Object
- TelegramMeetupBot::ParamsParser
- Defined in:
- lib/telegram_meetup_bot/params_parser.rb
Instance Attribute Summary collapse
-
#arg ⇒ Object
readonly
Returns the value of attribute arg.
Instance Method Summary collapse
-
#initialize(arg) ⇒ ParamsParser
constructor
A new instance of ParamsParser.
- #parse_date ⇒ Object
- #parse_month ⇒ Object
- #parse_time ⇒ Object
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
#arg ⇒ Object (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_date ⇒ Object
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_month ⇒ Object
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_time ⇒ Object
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 |