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 CHANGED
@@ -5,5 +5,6 @@ guard 'rspec', version: 2, cli: '-cfs' do
5
5
  watch(%r{spec/(.+)\.rb}) { |m| "spec/#{m[1]}.rb" }
6
6
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
7
  watch('spec/spec_helper.rb') { "spec/" }
8
+ watch('bin/scrabble-solver') { "spec/" }
8
9
  end
9
10
 
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
- The `--contains` and `--at` flags must be used in conjunction. They will not
67
- do anything if used separately. They will only return words that have the
68
- specified pattern at the specified location.
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
 
@@ -65,4 +65,8 @@ if letters.nil?
65
65
  end
66
66
 
67
67
  # If all is well, solve :)
68
- puts Scrabble::Solver.words_for letters, options
68
+ words = Scrabble::Solver.words_for(letters, options).sort do |word1, word2|
69
+ word1.length <=> word2.length
70
+ end
71
+
72
+ puts words
@@ -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] and options[:at]
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[options[:at].to_i - 1, options[:contains].length] == options[:contains]
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scrabble-solver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: '0.2'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: