scrabble-solver 0.1.1 → 0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Guardfile +1 -0
- data/README.md +11 -3
- data/bin/scrabble-solver +5 -1
- data/lib/scrabble-solver/solver.rb +9 -2
- data/spec/scrabble-solver/solver_spec.rb +41 -0
- metadata +1 -1
data/Guardfile
CHANGED
data/README.md
CHANGED
@@ -63,9 +63,17 @@ your Z is the first letter in the word, check this out:
|
|
63
63
|
|
64
64
|
$ scrabble-solver zloogsti --contains z --at 1
|
65
65
|
|
66
|
-
|
67
|
-
|
68
|
-
|
66
|
+
You can also use wildcards in the `--contains` flag:
|
67
|
+
|
68
|
+
$ scrabble-solver zloogsti --contains z?o --at 1
|
69
|
+
|
70
|
+
This will match z, anything, o and then anything after that. So "zoo"
|
71
|
+
will match beautifully.
|
72
|
+
|
73
|
+
If you don't feel like specifying an `--at` flag, you don't have to.
|
74
|
+
This will return "zoology" just fine:
|
75
|
+
|
76
|
+
$ scrabble-solver zlogoyo --contains gy
|
69
77
|
|
70
78
|
# Word lists
|
71
79
|
|
data/bin/scrabble-solver
CHANGED
@@ -98,9 +98,16 @@ module Scrabble
|
|
98
98
|
end
|
99
99
|
|
100
100
|
# Filter words that contain a specific sequence at a given 1-based index.
|
101
|
-
if options[:contains]
|
101
|
+
if options[:contains]
|
102
|
+
# Generate a regex to match against the string. This regex will replace
|
103
|
+
# question marks with dots, so that they match any character. This
|
104
|
+
# gives the user a lot of power with the --contains --at combo.
|
105
|
+
regex = ''
|
106
|
+
regex += ('^' + ('.' * (options[:at].to_i - 1))) if options[:at]
|
107
|
+
regex += options[:contains].gsub('?', '.')
|
108
|
+
regex = Regexp.new regex
|
102
109
|
words.keep_if do |word|
|
103
|
-
word
|
110
|
+
word =~ regex
|
104
111
|
end
|
105
112
|
end
|
106
113
|
|
@@ -89,6 +89,27 @@ module Scrabble
|
|
89
89
|
words.length.should be > 0, "No words scanned."
|
90
90
|
end
|
91
91
|
|
92
|
+
it "should be able to use wildcards in --contains" do
|
93
|
+
words = Solver.words_for "diegti?wj", contains: "g?t", at: "3"
|
94
|
+
words.each do |word|
|
95
|
+
word.should match /^..g.t/
|
96
|
+
end
|
97
|
+
|
98
|
+
# Ensure that some words were actually checked in the above loop.
|
99
|
+
words.length.should be > 0, "No words scanned."
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should be able to use --contains without --at" do
|
103
|
+
words = Solver.words_for "diegti?wj", contains: "g?t"
|
104
|
+
words.each do |word|
|
105
|
+
word.should match /g.t/
|
106
|
+
end
|
107
|
+
|
108
|
+
# Ensure that some words were actually checked in the above loop.
|
109
|
+
words.length.should be > 0, "No words scanned."
|
110
|
+
end
|
111
|
+
|
112
|
+
|
92
113
|
it "should be able to take a new word file if specified" do
|
93
114
|
words = Solver.words_for "????", word_file: test_word_file
|
94
115
|
words.should be_empty
|
@@ -172,6 +193,26 @@ module Scrabble
|
|
172
193
|
words.length.should be > 0, "No words scanned."
|
173
194
|
end
|
174
195
|
|
196
|
+
it "should be able to use wildcards in --contains" do
|
197
|
+
words = `#{executable} diegti?wj --contains g?t --at 3`.split(/\n/)
|
198
|
+
words.each do |word|
|
199
|
+
word.should match /^..g.t/
|
200
|
+
end
|
201
|
+
|
202
|
+
# Ensure that some words were actually checked in the above loop.
|
203
|
+
words.length.should be > 0, "No words scanned."
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should be able to use --contains without --at" do
|
207
|
+
words = `#{executable} diegti?wj --contains g?t`.split(/\n/)
|
208
|
+
words.each do |word|
|
209
|
+
word.should match /g.t/
|
210
|
+
end
|
211
|
+
|
212
|
+
# Ensure that some words were actually checked in the above loop.
|
213
|
+
words.length.should be > 0, "No words scanned."
|
214
|
+
end
|
215
|
+
|
175
216
|
it "should be able to take a new word file if specified" do
|
176
217
|
words = `#{executable} ???? --word-file #{test_word_file}`.split(/\n/)
|
177
218
|
words.should be_empty
|