Class: Perquackey::Dictionary

Inherits:
Object
  • Object
show all
Defined in:
lib/perquackey/dictionary.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDictionary

Returns a new instance of Dictionary.



7
8
9
# File 'lib/perquackey/dictionary.rb', line 7

def initialize
  @word_list = Perquackey.datadir.join('dict', 'TWL06.txt')
end

Class Method Details

.words(letters) ⇒ Object



3
4
5
# File 'lib/perquackey/dictionary.rb', line 3

def self.words(letters)
  new.words(letters)
end

Instance Method Details

#words(letters) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/perquackey/dictionary.rb', line 11

def words(letters)
  anagrams = @word_list.open do |stream|
    stream.extend(Anagrams)
    stream.enum_for(:each_anagram, letters).to_a
  end

  minimum = (letters.length <= 10) ? 3 : 4
  anagrams.reject { |anagram| anagram.length < minimum }
end