class TelegramMeetupBot::Commands::Base
Attributes
message[R]
Public Class Methods
new(message)
click to toggle source
# File lib/telegram_meetup_bot/commands/base.rb, line 6 def initialize(message) @message = message end
Public Instance Methods
command()
click to toggle source
# File lib/telegram_meetup_bot/commands/base.rb, line 14 def command @command ||= if COMMANDS.include?(message.command) message.command end end
exec()
click to toggle source
# File lib/telegram_meetup_bot/commands/base.rb, line 10 def exec fail NotImplementedError, 'This method should be overriden' end
Private Instance Methods
build_response(args = {}) { |response| ... }
click to toggle source
# File lib/telegram_meetup_bot/commands/base.rb, line 56 def build_response(args = {}) response_key = args.fetch(:key) { command } response = Initializers::ResponsesLoader.responses[response_key].dup response.gsub!('%first_name%', author.first_name) response.gsub!('%date%', args[:date].strftime('%d %h %Y')) if args[:date] response.gsub!('%date%', args[:month].strftime('%h %Y')) if args[:month] response.gsub!('%username%', args[:username]) if args[:username] block_given? ? yield(response) : response end
date_has_error?(date)
click to toggle source
# File lib/telegram_meetup_bot/commands/base.rb, line 38 def date_has_error?(date) if date.nil? @error = build_response(key: 'wrong_date_format') elsif date < Date.today @error = build_response(key: 'old_date') end end
handle_date(date) { || ... }
click to toggle source
# File lib/telegram_meetup_bot/commands/base.rb, line 30 def handle_date(date, &block) if date_has_error?(date) @error else yield end end
list_response(args)
click to toggle source
# File lib/telegram_meetup_bot/commands/base.rb, line 46 def list_response(args) empty_key = args.fetch(:empty_key) { 'nobody' } if args.fetch(:list).empty? build_response(args.merge(key: empty_key)) else build_response(args) { |response| "#{response}\n#{args.fetch(:list)}" } end end
params()
click to toggle source
# File lib/telegram_meetup_bot/commands/base.rb, line 26 def params message.params end