class SlackNeuralyzer::Cleaner::Base

Attributes

args[R]
channel_type[R]
dict[R]
logger[R]

Public Class Methods

new(args, dict, logger) click to toggle source
# File lib/slack_neuralyzer/cleaner/base.rb, line 8
def initialize(args, dict, logger)
  @args   = args
  @dict   = dict
  @logger = logger
  reset_counter
  parse_to_ts(args.after, args.before)
end

Private Instance Methods

current_channel() click to toggle source
# File lib/slack_neuralyzer/cleaner/base.rb, line 43
def current_channel
  light_green("#{args.public_send(channel_type)} #{channel_type}")
end
delete_format() click to toggle source
# File lib/slack_neuralyzer/cleaner/base.rb, line 51
def delete_format
  args.execute ? '(delete) '.light_red : ''
end
finish_text(type) click to toggle source
# File lib/slack_neuralyzer/cleaner/base.rb, line 60
def finish_text(type)
  text = "\n#{light_green(counter)} #{type}(s) in #{current_channel} "
  if args.execute.nil? && counter.nonzero?
    text << 'will be deleted.'
    text << light_red("\nNow, you can rerun the command and use `-e | --execute` to actually delete the #{type}(s).")
  else
    text << 'have been deleted.'
  end
  text << light_blue("\nThe log file has been generated in the current directory") if args.log
  text
end
get_channel_id() click to toggle source
# File lib/slack_neuralyzer/cleaner/base.rb, line 24
def get_channel_id
  if args.channel
    @channel_type = 'channel'
    channel_id    = dict.find_channel_id(args.channel)
  elsif args.direct
    @channel_type = 'direct'
    user_id       = dict.find_user_id(args.direct)
    channel_id    = dict.find_im_id(user_id)
  elsif args.group
    @channel_type = 'group'
    channel_id    = dict.find_group_id(args.group)
  elsif args.mpdirect
    @channel_type = 'mpdirect'
    channel_id    = dict.find_mpim_id(args.mpdirect)
  end
  raise SlackApi::Errors::NotFoundError, "#{current_channel} not found." unless channel_id
  channel_id
end
get_user_id() click to toggle source
# File lib/slack_neuralyzer/cleaner/base.rb, line 18
def get_user_id
  user_id = args.user == 'all' ? -1 : dict.find_user_id(args.user)
  raise SlackApi::Errors::NotFoundError, "#{args.user} not found." unless args.bot || user_id
  user_id
end
not_have_any(type) click to toggle source
# File lib/slack_neuralyzer/cleaner/base.rb, line 55
def not_have_any(type)
  logger.info "#{current_channel} does not have any #{type}(s)"
  exit
end
time_format(time) click to toggle source
# File lib/slack_neuralyzer/cleaner/base.rb, line 47
def time_format(time)
  light_cyan("[#{parse_to_date(time)}]")
end