Created
May 28, 2017 07:57
-
-
Save phensalves/9826c1dd4def9e65ad67ec3f94dd8ced to your computer and use it in GitHub Desktop.
Helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module TweetsHelper | |
def build_tweets_hash tweets | |
@tweets_array = [] | |
tweets.each do |tweet| | |
tweet_hash = { | |
user: tweet['user']['screen_name'], | |
user_profile: ENV['TWITTER_URL'] + tweet['user']['id'].to_s, | |
followers_count: tweet['user']['followers_count'], | |
retweets: tweet['retweet_count'], | |
likes: tweet['favorite_count'], | |
content: tweet['text'], | |
tweet_datetime: tweet['created_at'] | |
} | |
@tweets_array << tweet_hash | |
end | |
end | |
def sort_most_relevants tweets_array | |
@tweets_sorted = tweets_array.sort_by{|tweet| [tweet[:followers_count], tweet[:retweets], tweet[:likes]]}.reverse | |
end | |
def group_tweets_by_user tweets | |
@tweets_grouped_by_user = tweets.group_by {|tweet| tweet[:user] } | |
end | |
def beautify_json_response json | |
JSON.pretty_generate(json) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment