class Ayadn::BlacklistWorkers

Public Class Methods

new() click to toggle source
# File lib/ayadn/blacklist.rb, line 46
def initialize
  Settings.load_config
  Settings.get_token
  Settings.init_config
  Logs.create_logger
  Databases.open_databases
  @workers = Workers.new
end

Public Instance Methods

add(args) click to toggle source
# File lib/ayadn/blacklist.rb, line 69
def add(args)
  begin
    type = args.shift
    case type
    when 'user', 'username', 'account'
      target = @workers.remove_arobase_if_present(args)
      Databases.add_to_blacklist('user', target)
      target = @workers.add_arobases_to_usernames args
      Logs.rec.info "Added '#{target}' to blacklist of users."
    when 'mention', 'mentions'
      target = @workers.remove_arobase_if_present(args)
      Databases.add_to_blacklist('mention', target)
      target = @workers.add_arobases_to_usernames args
      Logs.rec.info "Added '#{target}' to blacklist of mentions."
    when 'client', 'source'
      Databases.add_to_blacklist('client', args)
      Logs.rec.info "Added '#{args}' to blacklist of clients."
    when 'hashtag', 'tag'
      Databases.add_to_blacklist('hashtag', args)
      Logs.rec.info "Added '#{args}' to blacklist of hashtags."
    when 'word', 'keyword'
      args = args.map { |w| w.gsub(/[~:-;,?!\'&`^=+<>*%()\/"“”’°£$€.…]/, "") }
      Databases.add_to_blacklist('word', args)
      Logs.rec.info "Added '#{args}' to blacklist of words."
    else
      Status.new.wrong_arguments
    end
  end
end
clear() click to toggle source
# File lib/ayadn/blacklist.rb, line 55
def clear
  begin
    Status.new.ask_clear_blacklist
    input = STDIN.getch
    if input == 'y' || input == 'Y'
      Databases.clear_blacklist
      Logs.rec.info "Cleared the blacklist database."
    else
      Status.new.canceled
      exit
    end
  end
end
list(options) click to toggle source
# File lib/ayadn/blacklist.rb, line 127
def list(options)
  begin
    Settings.options.timeline.compact = true if options[:compact]
    show_list(options)
  end
end
remove(args) click to toggle source
# File lib/ayadn/blacklist.rb, line 99
def remove(args)
  begin
    type = args.shift
    case type
    when 'user', 'username', 'account'
      Databases.remove_from_blacklist('user', args)
      target = @workers.add_arobases_to_usernames(args)
      Logs.rec.info "Removed '#{type}:#{target}' from blacklist of users."
    when 'mention', 'mentions'
      Databases.remove_from_blacklist('mention', args)
      target = @workers.add_arobases_to_usernames(args)
      Logs.rec.info "Removed '#{target}' from blacklist of mentions."
    when 'client', 'source'
      Databases.remove_from_blacklist('client', args)
      Logs.rec.info "Removed '#{type}:#{args}' from blacklist."
    when 'hashtag', 'tag'
      Databases.remove_from_blacklist('hashtag', args)
      Logs.rec.info "Removed '#{type}:#{args}' from blacklist."
    when 'word', 'keyword'
      args = args.map { |w| w.gsub(/[~:-;,?!\'&`^=+<>*%()\/"“”’°£$€.…]/, "") }
      Databases.remove_from_blacklist('word', args)
      Logs.rec.info "Removed '#{type}:#{args}' from blacklist."
    else
      Status.new.wrong_arguments
    end
  end
end

Private Instance Methods

show_list(options) click to toggle source
# File lib/ayadn/blacklist.rb, line 136
def show_list(options)
  list = Databases.all_blacklist
  unless list.empty?
    if options[:raw]
      xx = list.map {|obj| [obj[0], obj[1].to_s.force_encoding("UTF-8")] }
      puts xx.to_json
    else
      puts "\n"
      puts Workers.new.build_blacklist_list(list)
      puts "\n"
    end
  else
    Status.new.empty_list
    exit
  end
end