# Turn it into an array of words words = text.split(" ")
# Remove simple words clean_words = [] words.each do |w| clean_words << w if not IGNORE_WORDS.include?(w) and not is_numeric?(w) end
# Count the number of ocurrences for the remaining count_hash = Hash.new(0) clean_words.each { |w| count_hash[w] += 1 } count_hash = count_hash.sort_by { |k,v| v }.reverse
result = "" count_hash[0,5].each { |k,v| result << "#{k} (value: #{v}) " } result end