spellingbee 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/.gitignore +3 -0
  2. data/Gemfile +3 -0
  3. data/LICENSE +20 -0
  4. data/README +40 -0
  5. data/Rakefile +2 -0
  6. data/dict/default.txt +2 -0
  7. data/doc/Gemfile.html +98 -0
  8. data/doc/LICENSE.html +117 -0
  9. data/doc/README.html +146 -0
  10. data/doc/Rakefile.html +95 -0
  11. data/doc/SpellingBee.html +586 -0
  12. data/doc/created.rid +8 -0
  13. data/doc/dict/default_txt.html +97 -0
  14. data/doc/images/brick.png +0 -0
  15. data/doc/images/brick_link.png +0 -0
  16. data/doc/images/bug.png +0 -0
  17. data/doc/images/bullet_black.png +0 -0
  18. data/doc/images/bullet_toggle_minus.png +0 -0
  19. data/doc/images/bullet_toggle_plus.png +0 -0
  20. data/doc/images/date.png +0 -0
  21. data/doc/images/find.png +0 -0
  22. data/doc/images/loadingAnimation.gif +0 -0
  23. data/doc/images/macFFBgHack.png +0 -0
  24. data/doc/images/package.png +0 -0
  25. data/doc/images/page_green.png +0 -0
  26. data/doc/images/page_white_text.png +0 -0
  27. data/doc/images/page_white_width.png +0 -0
  28. data/doc/images/plugin.png +0 -0
  29. data/doc/images/ruby.png +0 -0
  30. data/doc/images/tag_green.png +0 -0
  31. data/doc/images/wrench.png +0 -0
  32. data/doc/images/wrench_orange.png +0 -0
  33. data/doc/images/zoom.png +0 -0
  34. data/doc/index.html +80 -0
  35. data/doc/js/darkfish.js +116 -0
  36. data/doc/js/jquery.js +32 -0
  37. data/doc/js/quicksearch.js +114 -0
  38. data/doc/js/thickbox-compressed.js +10 -0
  39. data/doc/lib/spellingbee/version_rb.html +52 -0
  40. data/doc/lib/spellingbee_rb.html +52 -0
  41. data/doc/rdoc.css +706 -0
  42. data/lib/spellingbee.rb +94 -0
  43. data/lib/spellingbee/version.rb +3 -0
  44. data/spellingbee.gemspec +21 -0
  45. metadata +108 -0
data/doc/Rakefile.html ADDED
@@ -0,0 +1,95 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
+
5
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
6
+ <head>
7
+ <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
8
+
9
+ <title>File: Rakefile [RDoc Documentation]</title>
10
+
11
+ <link type="text/css" media="screen" href="./rdoc.css" rel="stylesheet" />
12
+
13
+ <script src="./js/jquery.js" type="text/javascript"
14
+ charset="utf-8"></script>
15
+ <script src="./js/thickbox-compressed.js" type="text/javascript"
16
+ charset="utf-8"></script>
17
+ <script src="./js/quicksearch.js" type="text/javascript"
18
+ charset="utf-8"></script>
19
+ <script src="./js/darkfish.js" type="text/javascript"
20
+ charset="utf-8"></script>
21
+ </head>
22
+
23
+ <body class="file">
24
+ <div id="metadata">
25
+ <div id="home-metadata">
26
+ <div id="home-section" class="section">
27
+ <h3 class="section-header">
28
+ <a href="./index.html">Home</a>
29
+ <a href="./index.html#classes">Classes</a>
30
+ <a href="./index.html#methods">Methods</a>
31
+ </h3>
32
+ </div>
33
+ </div>
34
+
35
+ <div id="project-metadata">
36
+
37
+
38
+ <div id="fileindex-section" class="section project-section">
39
+ <h3 class="section-header">Files</h3>
40
+ <ul>
41
+
42
+ <li class="file"><a href="./Gemfile.html">Gemfile</a></li>
43
+
44
+ <li class="file"><a href="./LICENSE.html">LICENSE</a></li>
45
+
46
+ <li class="file"><a href="./README.html">README</a></li>
47
+
48
+ <li class="file"><a href="./Rakefile.html">Rakefile</a></li>
49
+
50
+ <li class="file"><a href="./dict/default_txt.html">default.txt</a></li>
51
+
52
+ </ul>
53
+ </div>
54
+
55
+
56
+ <div id="classindex-section" class="section project-section">
57
+ <h3 class="section-header">Class Index
58
+ <span class="search-toggle"><img src="./images/find.png"
59
+ height="16" width="16" alt="[+]"
60
+ title="show/hide quicksearch" /></span></h3>
61
+ <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
62
+ <fieldset>
63
+ <legend>Quicksearch</legend>
64
+ <input type="text" name="quicksearch" value=""
65
+ class="quicksearch-field" />
66
+ </fieldset>
67
+ </form>
68
+
69
+ <ul class="link-list">
70
+
71
+ <li><a href="./SpellingBee.html">SpellingBee</a></li>
72
+
73
+ </ul>
74
+ <div id="no-class-search-results" style="display: none;">No matching classes.</div>
75
+ </div>
76
+
77
+
78
+ </div>
79
+ </div>
80
+
81
+ <div id="documentation">
82
+ <p>
83
+ require &#8216;bundler&#8217; Bundler::GemHelper.install_tasks
84
+ </p>
85
+
86
+ </div>
87
+
88
+ <div id="validator-badges">
89
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
90
+ <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
91
+ Rdoc Generator</a> 1.1.6</small>.</p>
92
+ </div>
93
+ </body>
94
+ </html>
95
+
@@ -0,0 +1,586 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
7
+
8
+ <title>Class: SpellingBee</title>
9
+
10
+ <link rel="stylesheet" href="./rdoc.css" type="text/css" media="screen" />
11
+
12
+ <script src="./js/jquery.js" type="text/javascript"
13
+ charset="utf-8"></script>
14
+ <script src="./js/thickbox-compressed.js" type="text/javascript"
15
+ charset="utf-8"></script>
16
+ <script src="./js/quicksearch.js" type="text/javascript"
17
+ charset="utf-8"></script>
18
+ <script src="./js/darkfish.js" type="text/javascript"
19
+ charset="utf-8"></script>
20
+
21
+ </head>
22
+ <body class="class">
23
+
24
+ <div id="metadata">
25
+ <div id="home-metadata">
26
+ <div id="home-section" class="section">
27
+ <h3 class="section-header">
28
+ <a href="./index.html">Home</a>
29
+ <a href="./index.html#classes">Classes</a>
30
+ <a href="./index.html#methods">Methods</a>
31
+ </h3>
32
+ </div>
33
+ </div>
34
+
35
+ <div id="file-metadata">
36
+ <div id="file-list-section" class="section">
37
+ <h3 class="section-header">In Files</h3>
38
+ <div class="section-body">
39
+ <ul>
40
+
41
+ <li><a href="./lib/spellingbee/version_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
42
+ class="thickbox" title="lib/spellingbee/version.rb">lib/spellingbee/version.rb</a></li>
43
+
44
+ <li><a href="./lib/spellingbee_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
45
+ class="thickbox" title="lib/spellingbee.rb">lib/spellingbee.rb</a></li>
46
+
47
+ </ul>
48
+ </div>
49
+ </div>
50
+
51
+
52
+ </div>
53
+
54
+ <div id="class-metadata">
55
+
56
+ <!-- Parent Class -->
57
+
58
+ <div id="parent-class-section" class="section">
59
+ <h3 class="section-header">Parent</h3>
60
+
61
+ <p class="link">Object</p>
62
+
63
+ </div>
64
+
65
+
66
+ <!-- Namespace Contents -->
67
+
68
+
69
+ <!-- Method Quickref -->
70
+
71
+ <div id="method-list-section" class="section">
72
+ <h3 class="section-header">Methods</h3>
73
+ <ul class="link-list">
74
+
75
+ <li><a href="#method-c-new">::new</a></li>
76
+
77
+ <li><a href="#method-i-correct">#correct</a></li>
78
+
79
+ <li><a href="#method-i-deletions">#deletions</a></li>
80
+
81
+ <li><a href="#method-i-insertions">#insertions</a></li>
82
+
83
+ <li><a href="#method-i-known">#known</a></li>
84
+
85
+ <li><a href="#method-i-replacements">#replacements</a></li>
86
+
87
+ <li><a href="#method-i-transpositions">#transpositions</a></li>
88
+
89
+ <li><a href="#method-i-variation_words">#variation_words</a></li>
90
+
91
+ </ul>
92
+ </div>
93
+
94
+
95
+ <!-- Included Modules -->
96
+
97
+ </div>
98
+
99
+ <div id="project-metadata">
100
+
101
+
102
+ <div id="fileindex-section" class="section project-section">
103
+ <h3 class="section-header">Files</h3>
104
+ <ul>
105
+
106
+ <li class="file"><a href="./Gemfile.html">Gemfile</a></li>
107
+
108
+ <li class="file"><a href="./LICENSE.html">LICENSE</a></li>
109
+
110
+ <li class="file"><a href="./README.html">README</a></li>
111
+
112
+ <li class="file"><a href="./Rakefile.html">Rakefile</a></li>
113
+
114
+ <li class="file"><a href="./dict/default_txt.html">default.txt</a></li>
115
+
116
+ </ul>
117
+ </div>
118
+
119
+
120
+ <div id="classindex-section" class="section project-section">
121
+ <h3 class="section-header">Class Index
122
+ <span class="search-toggle"><img src="./images/find.png"
123
+ height="16" width="16" alt="[+]"
124
+ title="show/hide quicksearch" /></span></h3>
125
+ <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
126
+ <fieldset>
127
+ <legend>Quicksearch</legend>
128
+ <input type="text" name="quicksearch" value=""
129
+ class="quicksearch-field" />
130
+ </fieldset>
131
+ </form>
132
+
133
+ <ul class="link-list">
134
+
135
+ <li><a href="./SpellingBee.html">SpellingBee</a></li>
136
+
137
+ </ul>
138
+ <div id="no-class-search-results" style="display: none;">No matching classes.</div>
139
+ </div>
140
+
141
+
142
+ </div>
143
+ </div>
144
+
145
+ <div id="documentation">
146
+ <h1 class="class">SpellingBee</h1>
147
+
148
+ <div id="description">
149
+
150
+ </div>
151
+
152
+ <!-- Constants -->
153
+
154
+ <div id="constants-list" class="section">
155
+ <h3 class="section-header">Constants</h3>
156
+ <dl>
157
+
158
+ <dt><a name="VERSION">VERSION</a></dt>
159
+
160
+ <dd class="description"></dd>
161
+
162
+
163
+ <dt><a name="DEFAULT_DICT">DEFAULT_DICT</a></dt>
164
+
165
+ <dd class="description"></dd>
166
+
167
+
168
+ </dl>
169
+ </div>
170
+
171
+
172
+ <!-- Attributes -->
173
+
174
+ <div id="attribute-method-details" class="method-section section">
175
+ <h3 class="section-header">Attributes</h3>
176
+
177
+
178
+ <div id="dict-words-attribute-method" class="method-detail">
179
+ <a name="dict_words"></a>
180
+
181
+ <a name="dict_words="></a>
182
+
183
+ <div class="method-heading attribute-method-heading">
184
+ <span class="method-name">dict_words</span><span
185
+ class="attribute-access-type">[RW]</span>
186
+ </div>
187
+
188
+ <div class="method-description">
189
+
190
+
191
+
192
+ </div>
193
+ </div>
194
+
195
+ <div id="dict-frequency-attribute-method" class="method-detail">
196
+ <a name="dict_frequency"></a>
197
+
198
+ <a name="dict_frequency="></a>
199
+
200
+ <div class="method-heading attribute-method-heading">
201
+ <span class="method-name">dict_frequency</span><span
202
+ class="attribute-access-type">[RW]</span>
203
+ </div>
204
+
205
+ <div class="method-description">
206
+
207
+
208
+
209
+ </div>
210
+ </div>
211
+
212
+ </div>
213
+
214
+
215
+ <!-- Methods -->
216
+
217
+ <div id="public-class-method-details" class="method-section section">
218
+ <h3 class="section-header">Public Class Methods</h3>
219
+
220
+
221
+ <div id="new-method" class="method-detail ">
222
+ <a name="method-c-new"></a>
223
+
224
+ <div class="method-heading">
225
+
226
+ <span class="method-name">new</span><span
227
+ class="method-args">(opts = {})</span>
228
+ <span class="method-click-advice">click to toggle source</span>
229
+
230
+ </div>
231
+
232
+ <div class="method-description">
233
+
234
+
235
+
236
+
237
+
238
+ <div class="method-source-code"
239
+ id="new-source">
240
+ <pre>
241
+ <span class="ruby-comment cmt"># File lib/spellingbee.rb, line 7</span>
242
+ 7: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">opts</span> = {})
243
+ 8: <span class="ruby-identifier">options</span> = { <span class="ruby-value">:source_text</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">DEFAULT_DICT</span> }.<span class="ruby-identifier">merge</span> <span class="ruby-identifier">opts</span>
244
+ 9: <span class="ruby-ivar">@dict_frequency</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">1</span>)
245
+ 10: <span class="ruby-ivar">@dict_words</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">options</span>[<span class="ruby-value">:source_text</span>]).<span class="ruby-identifier">read</span>.<span class="ruby-identifier">downcase</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp re">/[a-z]+/</span>)
246
+ 11: <span class="ruby-ivar">@dict_words</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">word</span><span class="ruby-operator">|</span> <span class="ruby-ivar">@dict_frequency</span>[<span class="ruby-identifier">word</span>] <span class="ruby-operator">+=</span> <span class="ruby-value">1</span> }
247
+ 12: <span class="ruby-keyword kw">end</span></pre>
248
+ </div>
249
+
250
+ </div>
251
+
252
+
253
+
254
+
255
+ </div>
256
+
257
+
258
+ </div>
259
+
260
+ <div id="public-instance-method-details" class="method-section section">
261
+ <h3 class="section-header">Public Instance Methods</h3>
262
+
263
+
264
+ <div id="correct-method" class="method-detail ">
265
+ <a name="method-i-correct"></a>
266
+
267
+ <div class="method-heading">
268
+
269
+ <span class="method-name">correct</span><span
270
+ class="method-args">(word)</span>
271
+ <span class="method-click-advice">click to toggle source</span>
272
+
273
+ </div>
274
+
275
+ <div class="method-description">
276
+
277
+ <p>
278
+ Returns the suggestion for the correction. If the word is found in the
279
+ dictionary, it is returned, otherwise the word closest to it is returned.
280
+ If there are no spelling suggestions, the same word is returned.
281
+ </p>
282
+ <p>
283
+ Example:
284
+ </p>
285
+ <pre>
286
+
287
+ s = Spellingbee.new
288
+ s.correct &quot;spelling&quot; #=&gt; [&quot;spelling&quot;] -&gt; word from dictionary
289
+ s.correct &quot;speling&quot; #=&gt; [&quot;spelling&quot;] -&gt; corrected spelling
290
+ s.correct &quot;qqqqqq&quot; #=&gt; [&quot;qqqqqq&quot;] -&gt; no suggestions</pre>
291
+
292
+
293
+
294
+ <div class="method-source-code"
295
+ id="correct-source">
296
+ <pre>
297
+ <span class="ruby-comment cmt"># File lib/spellingbee.rb, line 90</span>
298
+ 90: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">correct</span> <span class="ruby-identifier">word</span>
299
+ 91: <span class="ruby-identifier">known</span> [<span class="ruby-identifier">word</span>] <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">known</span>(<span class="ruby-identifier">variation_words</span> <span class="ruby-identifier">word</span>) <span class="ruby-keyword kw">or</span> [<span class="ruby-identifier">word</span>]
300
+ 92: <span class="ruby-keyword kw">end</span></pre>
301
+ </div>
302
+
303
+ </div>
304
+
305
+
306
+
307
+
308
+ </div>
309
+
310
+
311
+ <div id="deletions-method" class="method-detail ">
312
+ <a name="method-i-deletions"></a>
313
+
314
+ <div class="method-heading">
315
+
316
+ <span class="method-name">deletions</span><span
317
+ class="method-args">(word)</span>
318
+ <span class="method-click-advice">click to toggle source</span>
319
+
320
+ </div>
321
+
322
+ <div class="method-description">
323
+
324
+ <p>
325
+ Returns all the combinations of the word with one character removed
326
+ </p>
327
+ <p>
328
+ Example:
329
+ </p>
330
+ <pre>
331
+ deletions(&quot;word&quot;) #=&gt; [&quot;ord&quot;, &quot;wrd&quot;, &quot;wod&quot;, &quot;wor&quot;]</pre>
332
+
333
+
334
+
335
+ <div class="method-source-code"
336
+ id="deletions-source">
337
+ <pre>
338
+ <span class="ruby-comment cmt"># File lib/spellingbee.rb, line 19</span>
339
+ 19: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">deletions</span> <span class="ruby-identifier">word</span>
340
+ 20: <span class="ruby-identifier">n</span> = <span class="ruby-identifier">word</span>.<span class="ruby-identifier">length</span>
341
+ 21: <span class="ruby-identifier">deletion</span> = (<span class="ruby-value">0</span><span class="ruby-operator">...</span><span class="ruby-identifier">n</span>).<span class="ruby-identifier">collect</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-identifier">word</span>[<span class="ruby-value">0</span><span class="ruby-operator">...</span><span class="ruby-identifier">i</span>]<span class="ruby-operator">+</span><span class="ruby-identifier">word</span>[<span class="ruby-identifier">i</span><span class="ruby-operator">+</span><span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">1</span>] }
342
+ 22: <span class="ruby-keyword kw">end</span></pre>
343
+ </div>
344
+
345
+ </div>
346
+
347
+
348
+
349
+
350
+ </div>
351
+
352
+
353
+ <div id="insertions-method" class="method-detail ">
354
+ <a name="method-i-insertions"></a>
355
+
356
+ <div class="method-heading">
357
+
358
+ <span class="method-name">insertions</span><span
359
+ class="method-args">(word)</span>
360
+ <span class="method-click-advice">click to toggle source</span>
361
+
362
+ </div>
363
+
364
+ <div class="method-description">
365
+
366
+ <p>
367
+ Returns all variations of the word with an alphabet inserted between the
368
+ characters.
369
+ </p>
370
+ <p>
371
+ Example:
372
+ </p>
373
+ <pre>
374
+ insertions(&quot;word&quot;) #=&gt; [&quot;aword&quot;, &quot;bword&quot;, &quot;cword&quot; ... &quot;waord&quot;, &quot;wbord&quot; ... ]</pre>
375
+
376
+
377
+
378
+ <div class="method-source-code"
379
+ id="insertions-source">
380
+ <pre>
381
+ <span class="ruby-comment cmt"># File lib/spellingbee.rb, line 53</span>
382
+ 53: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">insertions</span> <span class="ruby-identifier">word</span>
383
+ 54: <span class="ruby-identifier">n</span> = <span class="ruby-identifier">word</span>.<span class="ruby-identifier">length</span>
384
+ 55: <span class="ruby-identifier">new_words</span> = []
385
+ 56: (<span class="ruby-identifier">n</span><span class="ruby-operator">+</span><span class="ruby-value">1</span>).<span class="ruby-identifier">times</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> (<span class="ruby-value str">'a'</span><span class="ruby-operator">..</span><span class="ruby-value str">'z'</span>).<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">l</span><span class="ruby-operator">|</span> <span class="ruby-identifier">new_words</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">word</span>[<span class="ruby-value">0</span><span class="ruby-operator">...</span><span class="ruby-identifier">i</span>]<span class="ruby-operator">+</span><span class="ruby-identifier">l</span>.<span class="ruby-identifier">chr</span><span class="ruby-operator">+</span><span class="ruby-identifier">word</span>[<span class="ruby-identifier">i</span><span class="ruby-operator">..</span><span class="ruby-value">1</span>] } }
386
+ 57: <span class="ruby-identifier">new_words</span>
387
+ 58: <span class="ruby-keyword kw">end</span></pre>
388
+ </div>
389
+
390
+ </div>
391
+
392
+
393
+
394
+
395
+ </div>
396
+
397
+
398
+ <div id="known-method" class="method-detail ">
399
+ <a name="method-i-known"></a>
400
+
401
+ <div class="method-heading">
402
+
403
+ <span class="method-name">known</span><span
404
+ class="method-args">(words)</span>
405
+ <span class="method-click-advice">click to toggle source</span>
406
+
407
+ </div>
408
+
409
+ <div class="method-description">
410
+
411
+ <p>
412
+ Selects the words from the list that are present in the dictionary.
413
+ </p>
414
+ <p>
415
+ Example:
416
+ </p>
417
+ <pre>
418
+ known [&quot;asdfgh&quot;, &quot;known&quot;, &quot;word&quot;, &quot;qqqq&quot;] #=&gt; [&quot;known&quot;, &quot;word&quot;] </pre>
419
+
420
+
421
+
422
+ <div class="method-source-code"
423
+ id="known-source">
424
+ <pre>
425
+ <span class="ruby-comment cmt"># File lib/spellingbee.rb, line 74</span>
426
+ 74: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">known</span> <span class="ruby-identifier">words</span>
427
+ 75: <span class="ruby-identifier">known_words</span> = <span class="ruby-identifier">words</span>.<span class="ruby-identifier">find_all</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">w</span><span class="ruby-operator">|</span> <span class="ruby-ivar">@dict_frequency</span>.<span class="ruby-identifier">has_key?</span> <span class="ruby-identifier">w</span> }
428
+ 76: <span class="ruby-identifier">known_words</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-operator">?</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">known_words</span>
429
+ 77: <span class="ruby-keyword kw">end</span></pre>
430
+ </div>
431
+
432
+ </div>
433
+
434
+
435
+
436
+
437
+ </div>
438
+
439
+
440
+ <div id="replacements-method" class="method-detail ">
441
+ <a name="method-i-replacements"></a>
442
+
443
+ <div class="method-heading">
444
+
445
+ <span class="method-name">replacements</span><span
446
+ class="method-args">(word)</span>
447
+ <span class="method-click-advice">click to toggle source</span>
448
+
449
+ </div>
450
+
451
+ <div class="method-description">
452
+
453
+ <p>
454
+ Returns all variations of the word with each character replaced by all
455
+ characters from &#8216;a&#8217; to &#8216;z&#8217;.
456
+ </p>
457
+ <p>
458
+ Example:
459
+ </p>
460
+ <pre>
461
+ replacements(&quot;word&quot;) #=&gt; [&quot;aord&quot;, &quot;bord&quot;, &quot;cord&quot;, ... &quot;ward&quot;, &quot;wbrd&quot; ...]</pre>
462
+
463
+
464
+
465
+ <div class="method-source-code"
466
+ id="replacements-source">
467
+ <pre>
468
+ <span class="ruby-comment cmt"># File lib/spellingbee.rb, line 40</span>
469
+ 40: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">replacements</span> <span class="ruby-identifier">word</span>
470
+ 41: <span class="ruby-identifier">n</span> = <span class="ruby-identifier">word</span>.<span class="ruby-identifier">length</span>
471
+ 42: <span class="ruby-identifier">new_words</span> = []
472
+ 43: <span class="ruby-identifier">n</span>.<span class="ruby-identifier">times</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> (<span class="ruby-value str">'a'</span><span class="ruby-operator">..</span><span class="ruby-value str">'z'</span>).<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">l</span><span class="ruby-operator">|</span> <span class="ruby-identifier">new_words</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">word</span>[<span class="ruby-value">0</span><span class="ruby-operator">...</span><span class="ruby-identifier">i</span>]<span class="ruby-operator">+</span><span class="ruby-identifier">l</span>.<span class="ruby-identifier">chr</span><span class="ruby-operator">+</span><span class="ruby-identifier">word</span>[<span class="ruby-identifier">i</span><span class="ruby-operator">+</span><span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">1</span>] } }
473
+ 44: <span class="ruby-identifier">new_words</span>
474
+ 45: <span class="ruby-keyword kw">end</span></pre>
475
+ </div>
476
+
477
+ </div>
478
+
479
+
480
+
481
+
482
+ </div>
483
+
484
+
485
+ <div id="transpositions-method" class="method-detail ">
486
+ <a name="method-i-transpositions"></a>
487
+
488
+ <div class="method-heading">
489
+
490
+ <span class="method-name">transpositions</span><span
491
+ class="method-args">(word)</span>
492
+ <span class="method-click-advice">click to toggle source</span>
493
+
494
+ </div>
495
+
496
+ <div class="method-description">
497
+
498
+ <p>
499
+ Returns all combinations of the word with adjacent words transposed.
500
+ </p>
501
+ <p>
502
+ Example:
503
+ </p>
504
+ <pre>
505
+ transpositions(&quot;word&quot;) #=&gt; [&quot;owrd&quot;, &quot;wrod&quot;, &quot;wodr&quot;]</pre>
506
+
507
+
508
+
509
+ <div class="method-source-code"
510
+ id="transpositions-source">
511
+ <pre>
512
+ <span class="ruby-comment cmt"># File lib/spellingbee.rb, line 29</span>
513
+ 29: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">transpositions</span> <span class="ruby-identifier">word</span>
514
+ 30: <span class="ruby-identifier">n</span> = <span class="ruby-identifier">word</span>.<span class="ruby-identifier">length</span>
515
+ 31: (<span class="ruby-value">0</span><span class="ruby-operator">...</span><span class="ruby-identifier">n</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>).<span class="ruby-identifier">collect</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-identifier">word</span>[<span class="ruby-value">0</span><span class="ruby-operator">...</span><span class="ruby-identifier">i</span>]<span class="ruby-operator">+</span><span class="ruby-identifier">word</span>[<span class="ruby-identifier">i</span><span class="ruby-operator">+</span><span class="ruby-value">1</span>,<span class="ruby-value">1</span>]<span class="ruby-operator">+</span><span class="ruby-identifier">word</span>[<span class="ruby-identifier">i</span>,<span class="ruby-value">1</span>]<span class="ruby-operator">+</span><span class="ruby-identifier">word</span>[<span class="ruby-identifier">i</span><span class="ruby-operator">+</span><span class="ruby-value">2</span><span class="ruby-operator">..</span><span class="ruby-value">1</span>] }
516
+ 32: <span class="ruby-keyword kw">end</span></pre>
517
+ </div>
518
+
519
+ </div>
520
+
521
+
522
+
523
+
524
+ </div>
525
+
526
+
527
+ <div id="variation-words-method" class="method-detail ">
528
+ <a name="method-i-variation_words"></a>
529
+
530
+ <div class="method-heading">
531
+
532
+ <span class="method-name">variation_words</span><span
533
+ class="method-args">(word)</span>
534
+ <span class="method-click-advice">click to toggle source</span>
535
+
536
+ </div>
537
+
538
+ <div class="method-description">
539
+
540
+ <p>
541
+ Returns the variations of the given spelling. This set will contain all the
542
+ possible variations of the spelling havind edit distance = 1. (Edit
543
+ distance is the number of edits it takes to obtain the second word from
544
+ the first.)
545
+ </p>
546
+
547
+
548
+
549
+ <div class="method-source-code"
550
+ id="variation-words-source">
551
+ <pre>
552
+ <span class="ruby-comment cmt"># File lib/spellingbee.rb, line 64</span>
553
+ 64: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">variation_words</span> <span class="ruby-identifier">word</span>
554
+ 65: ( <span class="ruby-identifier">deletions</span>(<span class="ruby-identifier">word</span>) <span class="ruby-operator">+</span> <span class="ruby-identifier">transpositions</span>(<span class="ruby-identifier">word</span>) <span class="ruby-operator">+</span> <span class="ruby-identifier">replacements</span>(<span class="ruby-identifier">word</span>) <span class="ruby-operator">+</span> <span class="ruby-identifier">insertions</span>(<span class="ruby-identifier">word</span>) ).<span class="ruby-identifier">uniq</span>
555
+ 66: <span class="ruby-keyword kw">end</span></pre>
556
+ </div>
557
+
558
+ </div>
559
+
560
+
561
+
562
+
563
+ </div>
564
+
565
+
566
+ </div>
567
+
568
+
569
+ </div>
570
+
571
+
572
+ <div id="rdoc-debugging-section-dump" class="debugging-section">
573
+
574
+ <p>Disabled; run with --debug to generate this.</p>
575
+
576
+ </div>
577
+
578
+ <div id="validator-badges">
579
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
580
+ <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
581
+ Rdoc Generator</a> 1.1.6</small>.</p>
582
+ </div>
583
+
584
+ </body>
585
+ </html>
586
+