Created
March 11, 2011 14:44
-
-
Save deyvin/865963 to your computer and use it in GitHub Desktop.
Ideia para um Trend Topic pessoal
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
#idéia inicial | |
class TrendTopics | |
attr_accessor :texto | |
def meu_trend_topic | |
words = texto.downcase.gsub(/[^a-z\s]/, "").split | |
hash_words = Hash.new(0) | |
words.each do |word| | |
if word.length > 3 | |
hash_words[word] += 1 | |
end | |
end | |
hash_words.sort_by {|a,b| b}.reverse.first(5) | |
end | |
end | |
a = TrendTopic.new | |
a.texto = "Ola deyvid me diga qual seu nome, vc se chama deyvid e seu nome realmente é deyvid" | |
a.meu_trend_topic | |
# => [["deyvid", 3], ["nome", 2], ["chama", 1], ["qual", 1], ["diga", 1]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment