Skip to content

Instantly share code, notes, and snippets.

@deyvin
Created March 11, 2011 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deyvin/865963 to your computer and use it in GitHub Desktop.
Save deyvin/865963 to your computer and use it in GitHub Desktop.
Ideia para um Trend Topic pessoal
#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