Module: WordStats::Words

Defined in:
lib/word_stats.rb

Class Method Summary collapse

Class Method Details

.nwords(n, text) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/word_stats.rb', line 42

def self.nwords(n,text)
  text = text.remove_punctuation.downcase
  text = text.split(/\s+/)
  nwords = Hash.new(0)
  for i in n-1..(text.length-1)
    nwords[(text[i-(n-1)..i]).join(' ').to_sym] += 1
  end
  nwords
end