Skip to content

Instantly share code, notes, and snippets.

@LNA
Last active August 29, 2015 13:57
Show Gist options
  • Save LNA/9517750 to your computer and use it in GitHub Desktop.
Save LNA/9517750 to your computer and use it in GitHub Desktop.
Violating Encapsulation
class MutualMentions
attr_accessor :file, :relevant_tweets
def initialize(file)
@file = file
@relevant_tweets = [] # Red flag
end
def tweets_involving(user)
file = File.readlines(@file)
@user_check = Regexp.new user
@relevant_tweets = file.grep(@user_check) # Pulling out data and putting it in another data structure. Noooooooo!
end
def mutual_mentions_between(first_user, second_user)
@handle_mentions = [] #Red flag
@second_user_grep = Regexp.new second_user
@second_user = second_user
mutual_tweets
first_order_connection?
end
private
def mutual_tweets # This method exists only to pull out data from an existing data structure (AGAIN) and put it in another (AGAIN). Noooooooo!
mutual_tweets = @relevant_tweets.grep(@second_user_grep).map {|word| word.split(' ')}
mutual_tweets.each do |tweet|
@handle_mentions << tweet.grep(@second_user_grep)*","
end
end
end
def first_order_connection? # This method exists only to ask the new data structure about data that was in the old one. WHAT WAS I THINKING???
if @handle_mentions.include?(@second_user + ":") && @handle_mentions.include?("@" + @second_user)
true
else # Poorly written. include? will return true of false; the if statment in not needed here.
false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment