class TwitterTopicBot::TweetFilterer

Attributes

max_num_hashtags[R]
max_num_mentions[R]

Public Class Methods

new(options = {}) click to toggle source
# File lib/twitter_topic_bot/tweet_filterer.rb, line 3
def initialize(options = {})
  @max_num_mentions = options.fetch(:max_num_mentions, 1)
  @max_num_hashtags = options.fetch(:max_num_hashtags, 3)
end

Public Instance Methods

acceptable_tweet?(tweet_str, allow_links: true) click to toggle source
# File lib/twitter_topic_bot/tweet_filterer.rb, line 8
def acceptable_tweet?(tweet_str, allow_links: true)
  return false if is_spammy_tweet?(tweet_str) ||
                  is_sketchy_tweet?(tweet_str) ||
                  has_too_many_mentions?(tweet_str) ||
                  has_too_many_hashtags?(tweet_str)

  allow_links || !contains_link?(tweet_str)
end

Private Instance Methods

has_too_many_hashtags?(tweet_str) click to toggle source
# File lib/twitter_topic_bot/tweet_filterer.rb, line 38
def has_too_many_hashtags?(tweet_str)
  num_hashtags = tweet_str.split.count do |word|
    word.start_with?('#')
  end
  num_hashtags > max_num_hashtags
end
has_too_many_mentions?(tweet_str) click to toggle source
# File lib/twitter_topic_bot/tweet_filterer.rb, line 31
def has_too_many_mentions?(tweet_str)
  num_mentions = tweet_str.split.count do |word|
    word.start_with?('@')
  end
  num_mentions > max_num_mentions
end
is_sketchy_tweet?(tweet_str) click to toggle source
# File lib/twitter_topic_bot/tweet_filterer.rb, line 27
def is_sketchy_tweet?(tweet_str)
  tweet_str.match(/(fuck)|(fetish)|(ass)|(gamergate)|(shit)|(bitch)|(cunt)|(rape)/i)
end
is_spammy_tweet?(tweet_str) click to toggle source
# File lib/twitter_topic_bot/tweet_filterer.rb, line 22
def is_spammy_tweet?(tweet_str)
  contains_link?(tweet_str) &&
    tweet_str.match(/(buy)|(e-?book)|(order)|(press)/i)
end