Class: GameIcons::DidYouMean

Inherits:
Object
  • Object
show all
Defined in:
lib/game_icons/did_you_mean.rb

Instance Method Summary collapse

Constructor Details

#initialize(names) ⇒ DidYouMean

Returns a new instance of DidYouMean.



5
6
7
# File 'lib/game_icons/did_you_mean.rb', line 5

def initialize(names)
  @letter_freqs = lex(names)
end

Instance Method Details

#query(q, result_size = 5) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/game_icons/did_you_mean.rb', line 9

def query(q, result_size = 5)
  q = scrub(q.downcase.strip)
  q_freq = char_freq(q)
  scores = Hash.new(0)
  @letter_freqs.each do |name, freq|
    scores[name] = score(freq, q_freq)
  end
  top(result_size, scores)
end