Class: Perquackey::Dictionary
- Inherits:
-
Object
- Object
- Perquackey::Dictionary
- Defined in:
- lib/perquackey/dictionary.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Dictionary
constructor
A new instance of Dictionary.
- #words(letters) ⇒ Object
Constructor Details
#initialize ⇒ Dictionary
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 |