Class: LetterPressIsNotAsGoodAsBoggle
- Inherits:
-
Object
- Object
- LetterPressIsNotAsGoodAsBoggle
show all
- Defined in:
- lib/letter_press_is_not_as_good_as_boggle.rb,
lib/letter_press_is_not_as_good_as_boggle/version.rb,
lib/letter_press_is_not_as_good_as_boggle/word_list.rb,
lib/letter_press_is_not_as_good_as_boggle/word_list/node.rb,
lib/letter_press_is_not_as_good_as_boggle/board_traverser.rb,
lib/letter_press_is_not_as_good_as_boggle/word_list/searcher.rb
Defined Under Namespace
Classes: BoardTraverser, WordList
Constant Summary
collapse
- VERSION =
'1.0.2'
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(all_words = LetterPressIsNotAsGoodAsBoggle.all_words, &definition) ⇒ LetterPressIsNotAsGoodAsBoggle
Returns a new instance of LetterPressIsNotAsGoodAsBoggle.
15
16
17
18
19
|
# File 'lib/letter_press_is_not_as_good_as_boggle.rb', line 15
def initialize(all_words=LetterPressIsNotAsGoodAsBoggle.all_words, &definition)
@guessed = []
self.searcher = WordList::Searcher.new WordList.new all_words
instance_eval &definition
end
|
Class Method Details
.all_words ⇒ Object
11
12
13
|
# File 'lib/letter_press_is_not_as_good_as_boggle.rb', line 11
def self.all_words
File.read(File.expand_path '../../data/word_list', __FILE__).split("\n")
end
|
Instance Method Details
#board(chars) ⇒ Object
21
22
23
|
# File 'lib/letter_press_is_not_as_good_as_boggle.rb', line 21
def board(chars)
self.chars = chars
end
|
#guessed(guessed = []) ⇒ Object
Also known as:
guesses
25
26
27
|
# File 'lib/letter_press_is_not_as_good_as_boggle.rb', line 25
def guessed(guessed=[])
@guessed = guessed
end
|
#words ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/letter_press_is_not_as_good_as_boggle.rb', line 30
def words
@words ||= begin
words = Set.new
board_traverser.each_with_recur do |word, char, recurser|
next unless searcher.has_child? char
searcher.down_to char do
words << word if searcher.on_word? && !@guessed.include?(word)
recurser.call
end
end
words.sort_by &:length
end
end
|