Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/string-stats-mf.rb

Instance Method Summary collapse

Instance Method Details

#unique_word_countObject



16
17
18
19
# File 'lib/string-stats-mf.rb', line 16

def unique_word_count
  # self.unique_words.count
  split(" ").uniq.count 
end

#unique_wordsObject



11
12
13
14
# File 'lib/string-stats-mf.rb', line 11

def unique_words
  # self.split(" ").uniq
  split(" ").uniq
end

#word_countObject



6
7
8
9
# File 'lib/string-stats-mf.rb', line 6

def word_count
  # self.split(" ").count 
  split(" ").count
end

#word_frequenciesObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/string-stats-mf.rb', line 21

def word_frequencies
freq = {}
split(" ").each do |word|
  freq[word.to_sym] ||= 0
  freq[word.to_sym] += 1
  end
  freq 
# # dan's way of using regex
#   freq = {}
#   split(" ").scan(/\w+/) do |key|
#     words[key] += 1
#   end
#   freq
end