spoonerize 0.0.5 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/README.md +103 -28
- data/doc/README_md.html +86 -26
- data/doc/Spoonerize/Cli.html +9 -8
- data/doc/Spoonerize/Spoonerism.html +182 -13
- data/doc/created.rid +8 -8
- data/doc/index.html +83 -24
- data/doc/js/search_index.js +1 -1
- data/doc/js/search_index.js.gz +0 -0
- data/doc/table_of_contents.html +24 -7
- data/lib/config/lazy_words.yml +2 -1
- data/lib/spoonerize/cli.rb +4 -4
- data/lib/spoonerize/spoonerism.rb +231 -162
- data/lib/spoonerize/version.rb +1 -1
- metadata +2 -3
- data/pkg/spoonerize-0.0.7.gem +0 -0
data/doc/created.rid
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
|
2
|
-
README.md
|
3
|
-
lib/spoonerize.rb Sat, 02 May 2020 22:
|
4
|
-
lib/spoonerize/bumper.rb Sat, 02 May 2020 22:
|
5
|
-
lib/spoonerize/cli.rb
|
6
|
-
lib/spoonerize/log.rb Sat, 02 May 2020 22:
|
7
|
-
lib/spoonerize/spoonerism.rb
|
8
|
-
lib/spoonerize/version.rb
|
1
|
+
Sun, 03 May 2020 21:49:14 -0500
|
2
|
+
README.md Sun, 03 May 2020 21:42:49 -0500
|
3
|
+
lib/spoonerize.rb Sat, 02 May 2020 22:24:00 -0500
|
4
|
+
lib/spoonerize/bumper.rb Sat, 02 May 2020 22:24:00 -0500
|
5
|
+
lib/spoonerize/cli.rb Sun, 03 May 2020 21:34:21 -0500
|
6
|
+
lib/spoonerize/log.rb Sat, 02 May 2020 22:24:00 -0500
|
7
|
+
lib/spoonerize/spoonerism.rb Sun, 03 May 2020 21:49:09 -0500
|
8
|
+
lib/spoonerize/version.rb Sun, 03 May 2020 21:34:21 -0500
|
data/doc/index.html
CHANGED
@@ -91,16 +91,20 @@
|
|
91
91
|
<main role="main">
|
92
92
|
|
93
93
|
|
94
|
-
<h1 id="label-Welcome+to+Spoonerize+--+a+word+game">Welcome to <a href="
|
94
|
+
<h1 id="label-Welcome+to+Spoonerize+--+a+word+game.">Welcome to <a href="Spoonerize.html"><code>Spoonerize</code></a> – a word game.<span><a href="#label-Welcome+to+Spoonerize+--+a+word+game.">¶</a> <a href="#top">↑</a></span></h1>
|
95
|
+
|
96
|
+
<p><a href="https://actions-badge.atrox.dev/evanthegrayt/spoonerize/goto?ref=master"><img src="https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fevanthegrayt%2Fspoonerize%2Fbadge%3Fref%3Dmaster&style=flat"></a> <a href="https://badge.fury.io/rb/spoonerize"><img src="https://badge.fury.io/rb/spoonerize.svg"></a> <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg"></a></p>
|
95
97
|
|
96
98
|
<blockquote>
|
97
|
-
<p>
|
99
|
+
<p>Spoonerism <em>[noun]</em> a verbal error in which a speaker accidentally transposes the initial sounds or letters of two or more words, often to humorous effect.</p>
|
98
100
|
</blockquote>
|
99
101
|
|
100
|
-
<p>
|
102
|
+
<p>View on <a href="https://github.com/evanthegrayt/spoonerize">Github</a> | <a href="https://evanthegrayt.github.io/spoonerize/">Github Pages</a> | <a href="https://rubygems.org/gems/spoonerize">RubyGems</a></p>
|
101
103
|
|
102
104
|
<h2 id="label-Table+of+Contents">Table of Contents<span><a href="#label-Table+of+Contents">¶</a> <a href="#top">↑</a></span></h2>
|
103
105
|
<ul><li>
|
106
|
+
<p><a href="#about">About</a></p>
|
107
|
+
</li><li>
|
104
108
|
<p><a href="#installation">Installation</a></p>
|
105
109
|
</li><li>
|
106
110
|
<p><a href="#automated">Automated</a></p>
|
@@ -109,13 +113,34 @@
|
|
109
113
|
</li><li>
|
110
114
|
<p><a href="#command-line-usage">Command Line Usage</a></p>
|
111
115
|
</li><li>
|
116
|
+
<p><a href="#config-file">Config file</a></p>
|
117
|
+
</li><li>
|
112
118
|
<p><a href="#api">API</a></p>
|
113
119
|
</li><li>
|
114
|
-
<p><a href="
|
120
|
+
<p><a href="https://evanthegrayt.github.io/spoonerize/doc/index.html">Documentation</a></p>
|
115
121
|
</li><li>
|
116
122
|
<p><a href="#self-promotion">Self-Promotion</a></p>
|
117
123
|
</li></ul>
|
118
124
|
|
125
|
+
<h2 id="label-About">About<span><a href="#label-About">¶</a> <a href="#top">↑</a></span></h2>
|
126
|
+
|
127
|
+
<p>We've all done it; someone says a phrase, and you flip the first few letters around, and sometimes, it makes an even funnier phrase. For example: “Tomb Raider” becomes “Romb Taider”. Well, when I was in high school, we took it further – probably too far – and made a rule set. This gem, which includes a command-line executable, follows those rules, which are:</p>
|
128
|
+
<ul><li>
|
129
|
+
<p>Each word drops its leading consonant group and takes the leading consonant group of the next word.</p>
|
130
|
+
</li><li>
|
131
|
+
<p>If the word has no leading consonants, nothing is dropped, but it still receives the next word's leading consonants if it has any.</p>
|
132
|
+
</li><li>
|
133
|
+
<p>If the next word has no leading consonants, the current word receives no consonants, but will still lose its own if it has any.</p>
|
134
|
+
</li><li>
|
135
|
+
<p>When being “lazy”, common words (“the”, “his”, etc.) remain unchanged.</p>
|
136
|
+
</li><li>
|
137
|
+
<p>If the word to pull from is excluded, that word is skipped, and you pull the leading consonants from the next non-excluded word.</p>
|
138
|
+
</li><li>
|
139
|
+
<p>“Q” and “U” should stay together (like “queen”).</p>
|
140
|
+
</li><li>
|
141
|
+
<p>A lot of the time, the words won't look how they're supposed to sound, as you go by how the word <em>used</em> to sound, not how it's spelled. For instance, <code>$ spoonerize two new cuties</code> becomes “no cew twuties”, but it would be pronounced “new coo tooties”, as the words retain their original sounds.</p>
|
142
|
+
</li></ul>
|
143
|
+
|
119
144
|
<h2 id="label-Installation">Installation<span><a href="#label-Installation">¶</a> <a href="#top">↑</a></span></h2>
|
120
145
|
|
121
146
|
<h3 id="label-Automated">Automated<span><a href="#label-Automated">¶</a> <a href="#top">↑</a></span></h3>
|
@@ -154,37 +179,71 @@ ln -s $PWD/bin/spoonerize /usr/local/bin/spoonerize
|
|
154
179
|
<p>If you find a phrase funny enough to save, you can pass the <code>-s</code> flag. This will write the results to the logfile. You can print your log file with the <code>-p</code> flag. It will show the original phrase, the end result, and the options used to get the results. For example:</p>
|
155
180
|
|
156
181
|
<pre>$ spoonerize -s not too shabby
|
157
|
-
Saving [tot shoo nabby] to /
|
182
|
+
Saving [tot shoo nabby] to ~/.cache/spoonerize/spoonerize.csv
|
158
183
|
|
159
184
|
$ spoonerize -rs not too shabby
|
160
|
-
Saving [shot noo tabby] to /
|
185
|
+
Saving [shot noo tabby] to ~/.cache/spoonerize/spoonerize.csv
|
161
186
|
|
162
187
|
$ spoonerize -p
|
163
188
|
not too shabby | tot shoo nabby | No Options
|
164
189
|
not too shabby | shot noo tabby | Reverse</pre>
|
165
190
|
|
166
|
-
<p>
|
191
|
+
<p>Here is a list of all available options:</p>
|
192
|
+
|
193
|
+
<pre>-r, --[no-]reverse Reverse flipping
|
194
|
+
-l, --[no-]lazy Skip small words
|
195
|
+
-m, --[no-]map Print words mapping
|
196
|
+
-p, --[no-]print Print all entries in the log
|
197
|
+
-s, --[no-]save Save results in log
|
198
|
+
--exclude=WORDS Words to skip</pre>
|
199
|
+
|
200
|
+
<h3 id="label-Config+File">Config File<span><a href="#label-Config+File">¶</a> <a href="#top">↑</a></span></h3>
|
201
|
+
|
202
|
+
<p>You can create a config file called <code>~/.spoonerize.yml</code>. In this file, you can change default options at runtime. Available settings are:</p>
|
203
|
+
|
204
|
+
<pre># Setting Default
|
205
|
+
excluded_words: []
|
206
|
+
lazy: false
|
207
|
+
reverse: false
|
208
|
+
logfile_name: '~/.cache/spoonerize/spoonerize.csv'</pre>
|
209
|
+
|
210
|
+
<p>Options set by this file can be overridden at runtime by the use of the executable's flags.</p>
|
167
211
|
|
168
212
|
<h2 id="label-API">API<span><a href="#label-API">¶</a> <a href="#top">↑</a></span></h2>
|
169
213
|
|
170
|
-
<p>
|
214
|
+
<p>The API is <a href="https://evanthegrayt.github.io/spoonerize/doc/index.html">fully documented</a>, but below are some quick examples of how you could use this in your ruby code.</p>
|
171
215
|
|
172
|
-
<
|
173
|
-
|
174
|
-
<
|
175
|
-
</
|
176
|
-
<
|
177
|
-
|
178
|
-
<
|
179
|
-
</
|
180
|
-
|
181
|
-
</
|
182
|
-
<
|
183
|
-
</
|
184
|
-
|
185
|
-
</
|
186
|
-
<
|
187
|
-
</
|
216
|
+
<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">'spoonerize'</span>
|
217
|
+
|
218
|
+
<span class="ruby-identifier">spoonerism</span> = <span class="ruby-constant">Spoonerize</span><span class="ruby-operator">::</span><span class="ruby-constant">Spoonerism</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">%w[not too shabby]</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span>
|
219
|
+
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">reverse</span> = <span class="ruby-keyword">true</span>
|
220
|
+
<span class="ruby-keyword">end</span>
|
221
|
+
|
222
|
+
<span class="ruby-identifier">spoonerism</span>.<span class="ruby-identifier">spoonerize</span>
|
223
|
+
<span class="ruby-comment"># => shot noo tabby</span>
|
224
|
+
|
225
|
+
<span class="ruby-identifier">spoonerism</span>.<span class="ruby-identifier">reverse</span> = <span class="ruby-keyword">false</span>
|
226
|
+
<span class="ruby-identifier">spoonerism</span>.<span class="ruby-identifier">spoonerize</span>
|
227
|
+
<span class="ruby-comment"># => tot shoo nabby</span>
|
228
|
+
|
229
|
+
<span class="ruby-identifier">spoonerism</span>.<span class="ruby-identifier">logfile_name</span> = <span class="ruby-string">'~/.cache/spoonerize/spoonerize.csv'</span>
|
230
|
+
<span class="ruby-identifier">spoonerism</span>.<span class="ruby-identifier">save</span>
|
231
|
+
</pre>
|
232
|
+
|
233
|
+
<p>You can also use the <a href="#config-file">config file</a>, either by passing it at initialization, or via the setter. The config file will be automatically loaded if passed at initialization, before the instance is yielded so you can still change the values via the block. If set via the setter, you must call <code>#load_config_file</code>.</p>
|
234
|
+
|
235
|
+
<pre class="ruby"><span class="ruby-comment"># Config file would be automatically loaded before block is executed.</span>
|
236
|
+
<span class="ruby-identifier">s</span> = <span class="ruby-constant">Spoonerise</span><span class="ruby-operator">::</span><span class="ruby-constant">Spoonerism</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">%w[not too shabby]</span>, <span class="ruby-string">'~/.spoonerize.yml'</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">sp</span><span class="ruby-operator">|</span>
|
237
|
+
<span class="ruby-identifier">sp</span>.<span class="ruby-identifier">reverse</span> = <span class="ruby-keyword">true</span>
|
238
|
+
<span class="ruby-keyword">end</span>
|
239
|
+
|
240
|
+
<span class="ruby-comment"># Config file would need to be manually loaded.</span>
|
241
|
+
<span class="ruby-identifier">s</span> = <span class="ruby-constant">Spoonerise</span><span class="ruby-operator">::</span><span class="ruby-constant">Spoonerism</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">%w[not too shabby]</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">sp</span><span class="ruby-operator">|</span>
|
242
|
+
<span class="ruby-identifier">sp</span>.<span class="ruby-identifier">config_file</span> = <span class="ruby-string">'~/.spoonerize.yml'</span>
|
243
|
+
<span class="ruby-keyword">end</span>
|
244
|
+
|
245
|
+
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">load_config_file</span>
|
246
|
+
</pre>
|
188
247
|
|
189
248
|
<h2 id="label-Self+Promotion">Self Promotion<span><a href="#label-Self+Promotion">¶</a> <a href="#top">↑</a></span></h2>
|
190
249
|
|
data/doc/js/search_index.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
var search_data = {"index":{"searchIndex":["spoonerize","bumper","cli","log","spoonerism","all_excluded_words()","bump()","contents()","each()","enough_flippable_words?()","execute()","lazy?()","longest_word_length()","map?()","new()","new()","new()","new()","print?()","print_log()","print_mappings()","reverse?()","reverse?()","save()","save?()","size()","spoonerism()","spoonerize()","to_h()","to_json()","to_s()","write()","readme"],"longSearchIndex":["spoonerize","spoonerize::bumper","spoonerize::cli","spoonerize::log","spoonerize::spoonerism","spoonerize::spoonerism#all_excluded_words()","spoonerize::bumper#bump()","spoonerize::log#contents()","spoonerize::log#each()","spoonerize::spoonerism#enough_flippable_words?()","spoonerize::cli::execute()","spoonerize::spoonerism#lazy?()","spoonerize::cli#longest_word_length()","spoonerize::cli#map?()","spoonerize::bumper::new()","spoonerize::cli::new()","spoonerize::log::new()","spoonerize::spoonerism::new()","spoonerize::cli#print?()","spoonerize::cli#print_log()","spoonerize::cli#print_mappings()","spoonerize::bumper#reverse?()","spoonerize::spoonerism#reverse?()","spoonerize::spoonerism#save()","spoonerize::cli#save?()","spoonerize::log#size()","spoonerize::cli#spoonerism()","spoonerize::spoonerism#spoonerize()","spoonerize::spoonerism#to_h()","spoonerize::spoonerism#to_json()","spoonerize::spoonerism#to_s()","spoonerize::log#write()",""],"info":[["Spoonerize","","Spoonerize.html","","<p>The main namespace for the gem.\n"],["Spoonerize::Bumper","","Spoonerize/Bumper.html","","<p>Class that handles bumping an index.\n"],["Spoonerize::Cli","","Spoonerize/Cli.html","","<p>The class for handling the command-line interface.\n"],["Spoonerize::Log","","Spoonerize/Log.html","","<p>Class that handles reading/writing logs.\n"],["Spoonerize::Spoonerism","","Spoonerize/Spoonerism.html","","<p>The main word-flipper.\n"],["all_excluded_words","Spoonerize::Spoonerism","Spoonerize/Spoonerism.html#method-i-all_excluded_words","()","<p>Returns an array of words to exclude by combining three arrays:\n<p>Any word in the passed arguments that's …\n"],["bump","Spoonerize::Bumper","Spoonerize/Bumper.html#method-i-bump","()","<p>Increments/Decrements the bumper. If on the last element of the words array, sets the bumper to 0. We …\n"],["contents","Spoonerize::Log","Spoonerize/Log.html#method-i-contents","()","<p>The contents of the log file.\n<p>@return [Array]\n"],["each","Spoonerize::Log","Spoonerize/Log.html#method-i-each","()","<p>Iterate through each line of the file.\n<p>@return [Array]\n"],["enough_flippable_words?","Spoonerize::Spoonerism","Spoonerize/Spoonerism.html#method-i-enough_flippable_words-3F","()","<p>Returns true if there are more than one non-excluded word to flip\n"],["execute","Spoonerize::Cli","Spoonerize/Cli.html#method-c-execute","(options = [])","<p>Creates an instance of <code>
|
1
|
+
var search_data = {"index":{"searchIndex":["spoonerize","bumper","cli","log","spoonerism","all_excluded_words()","bump()","config_file=()","config_file_loaded?()","contents()","each()","enough_flippable_words?()","execute()","lazy?()","load_config_file()","longest_word_length()","map?()","new()","new()","new()","new()","print?()","print_log()","print_mappings()","reverse?()","reverse?()","save()","save?()","size()","spoonerism()","spoonerize()","to_h()","to_json()","to_s()","write()","readme"],"longSearchIndex":["spoonerize","spoonerize::bumper","spoonerize::cli","spoonerize::log","spoonerize::spoonerism","spoonerize::spoonerism#all_excluded_words()","spoonerize::bumper#bump()","spoonerize::spoonerism#config_file=()","spoonerize::spoonerism#config_file_loaded?()","spoonerize::log#contents()","spoonerize::log#each()","spoonerize::spoonerism#enough_flippable_words?()","spoonerize::cli::execute()","spoonerize::spoonerism#lazy?()","spoonerize::spoonerism#load_config_file()","spoonerize::cli#longest_word_length()","spoonerize::cli#map?()","spoonerize::bumper::new()","spoonerize::cli::new()","spoonerize::log::new()","spoonerize::spoonerism::new()","spoonerize::cli#print?()","spoonerize::cli#print_log()","spoonerize::cli#print_mappings()","spoonerize::bumper#reverse?()","spoonerize::spoonerism#reverse?()","spoonerize::spoonerism#save()","spoonerize::cli#save?()","spoonerize::log#size()","spoonerize::cli#spoonerism()","spoonerize::spoonerism#spoonerize()","spoonerize::spoonerism#to_h()","spoonerize::spoonerism#to_json()","spoonerize::spoonerism#to_s()","spoonerize::log#write()",""],"info":[["Spoonerize","","Spoonerize.html","","<p>The main namespace for the gem.\n"],["Spoonerize::Bumper","","Spoonerize/Bumper.html","","<p>Class that handles bumping an index.\n"],["Spoonerize::Cli","","Spoonerize/Cli.html","","<p>The class for handling the command-line interface.\n"],["Spoonerize::Log","","Spoonerize/Log.html","","<p>Class that handles reading/writing logs.\n"],["Spoonerize::Spoonerism","","Spoonerize/Spoonerism.html","","<p>The main word-flipper.\n"],["all_excluded_words","Spoonerize::Spoonerism","Spoonerize/Spoonerism.html#method-i-all_excluded_words","()","<p>Returns an array of words to exclude by combining three arrays:\n<p>Any word in the passed arguments that's …\n"],["bump","Spoonerize::Bumper","Spoonerize/Bumper.html#method-i-bump","()","<p>Increments/Decrements the bumper. If on the last element of the words array, sets the bumper to 0. We …\n"],["config_file=","Spoonerize::Spoonerism","Spoonerize/Spoonerism.html#method-i-config_file-3D","(config_file)","<p>Setter for <code>config_file</code>. Must be expanded in case the user uses `~` for home.\n<p>@param [String] file\n<p>@return …\n"],["config_file_loaded?","Spoonerize::Spoonerism","Spoonerize/Spoonerism.html#method-i-config_file_loaded-3F","()","<p>Has a config file been loaded?\n<p>@return [Boolean]\n"],["contents","Spoonerize::Log","Spoonerize/Log.html#method-i-contents","()","<p>The contents of the log file.\n<p>@return [Array]\n"],["each","Spoonerize::Log","Spoonerize/Log.html#method-i-each","()","<p>Iterate through each line of the file.\n<p>@return [Array]\n"],["enough_flippable_words?","Spoonerize::Spoonerism","Spoonerize/Spoonerism.html#method-i-enough_flippable_words-3F","()","<p>Returns true if there are more than one non-excluded word to flip\n"],["execute","Spoonerize::Cli","Spoonerize/Cli.html#method-c-execute","(options = [])","<p>Creates an instance of <code>Spoonerism</code> and runs what the user requested.\n<p>@param [Array] options\n"],["lazy?","Spoonerize::Spoonerism","Spoonerize/Spoonerism.html#method-i-lazy-3F","()","<p>Should the lazy words be excluded?\n"],["load_config_file","Spoonerize::Spoonerism","Spoonerize/Spoonerism.html#method-i-load_config_file","()","<p>Loads the config file\n<p>@return [Hash] The config options\n"],["longest_word_length","Spoonerize::Cli","Spoonerize/Cli.html#method-i-longest_word_length","()","<p>The length of the longest word in the phrase.\n<p>@return [Integer]\n"],["map?","Spoonerize::Cli","Spoonerize/Cli.html#method-i-map-3F","()","<p>Should we print the mappings to the command line?\n<p>@return [Boolean]\n"],["new","Spoonerize::Bumper","Spoonerize/Bumper.html#method-c-new","(initial_value, max_value, reverse = false)","<p>Sets the bumper relative to the current index of words array. The value is automatically bumped once …\n"],["new","Spoonerize::Cli","Spoonerize/Cli.html#method-c-new","(options)","<p>Create instance of <code>Cli</code>\n<p>@param [Array] options\n<p>@return [self]\n"],["new","Spoonerize::Log","Spoonerize/Log.html#method-c-new","(file)","<p>Constructor for Log.\n<p>@param [String] file\n<p>@return [Spoonerize::Log]\n"],["new","Spoonerize::Spoonerism","Spoonerize/Spoonerism.html#method-c-new","(words, config_file = nil)","<p>Initialize instance. You can also use the <code>config_file</code> either by passing it at initialization, or via …\n"],["print?","Spoonerize::Cli","Spoonerize/Cli.html#method-i-print-3F","()","<p>Should we print to the command line?\n<p>@return [Boolean]\n"],["print_log","Spoonerize::Cli","Spoonerize/Cli.html#method-i-print_log","()","<p>Print the log file contents to the command line.\n<p>@return [nil]\n"],["print_mappings","Spoonerize::Cli","Spoonerize/Cli.html#method-i-print_mappings","()","<p>Print the hash of mappings to the command line.\n<p>@return [nil]\n"],["reverse?","Spoonerize::Bumper","Spoonerize/Bumper.html#method-i-reverse-3F","()","<p>Should we decrement instead of increment?\n<p>@return [Boolean]\n"],["reverse?","Spoonerize::Spoonerism","Spoonerize/Spoonerism.html#method-i-reverse-3F","()","<p>Should the words flip the other direction?\n"],["save","Spoonerize::Spoonerism","Spoonerize/Spoonerism.html#method-i-save","()","<p>Saves the flipped words to the log file, along with the options\n"],["save?","Spoonerize::Cli","Spoonerize/Cli.html#method-i-save-3F","()","<p>Should we save to the log file?\n<p>@return [Boolean]\n"],["size","Spoonerize::Log","Spoonerize/Log.html#method-i-size","()","<p>Number of entries in the file.\n<p>@return [Integer]\n"],["spoonerism","Spoonerize::Cli","Spoonerize/Cli.html#method-i-spoonerism","()","<p>Sets up an instance of <code>Spoonerize::Spoonerism</code> and passes all user preferences.\n<p>@return [Spoonerize::Spoonerism] …\n"],["spoonerize","Spoonerize::Spoonerism","Spoonerize/Spoonerism.html#method-i-spoonerize","()","<p>Iterates through words array, and maps its elements to the output of flip_words. Returns results as an …\n"],["to_h","Spoonerize::Spoonerism","Spoonerize/Spoonerism.html#method-i-to_h","()","<p>Returns hash of the original words mapped to their flipped counterparts.\n"],["to_json","Spoonerize::Spoonerism","Spoonerize/Spoonerism.html#method-i-to_json","()","<p>Same as to_h, but as json.\n"],["to_s","Spoonerize::Spoonerism","Spoonerize/Spoonerism.html#method-i-to_s","()","<p>Returns spoonerize array as a joined string.\n"],["write","Spoonerize::Log","Spoonerize/Log.html#method-i-write","(row)","<p>Writes a line to the log.\n<p>@param [Array] row\n<p>@return [Array]\n"],["README","","README_md.html","","<p>Welcome to Spoonerize – a word game.\n<p><img src=\"https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fevanthegrayt%2Fspoonerize%2Fbadge%3Fref%3Dmaster&style=flat\"> …\n\n<blockquote>"]]}}
|
data/doc/js/search_index.js.gz
CHANGED
Binary file
|
data/doc/table_of_contents.html
CHANGED
@@ -37,10 +37,12 @@
|
|
37
37
|
|
38
38
|
<ul>
|
39
39
|
|
40
|
-
<li><a href="README_md.html#label-Welcome+to+Spoonerize+--+a+word+game">Welcome to
|
40
|
+
<li><a href="README_md.html#label-Welcome+to+Spoonerize+--+a+word+game.">Welcome to Spoonerize – a word game.</a>
|
41
41
|
|
42
42
|
<li><a href="README_md.html#label-Table+of+Contents">Table of Contents</a>
|
43
43
|
|
44
|
+
<li><a href="README_md.html#label-About">About</a>
|
45
|
+
|
44
46
|
<li><a href="README_md.html#label-Installation">Installation</a>
|
45
47
|
|
46
48
|
<li><a href="README_md.html#label-Automated">Automated</a>
|
@@ -49,9 +51,9 @@
|
|
49
51
|
|
50
52
|
<li><a href="README_md.html#label-Command+Line+Usage">Command Line Usage</a>
|
51
53
|
|
52
|
-
<li><a href="README_md.html#label-
|
54
|
+
<li><a href="README_md.html#label-Config+File">Config File</a>
|
53
55
|
|
54
|
-
<li><a href="README_md.html#label-
|
56
|
+
<li><a href="README_md.html#label-API">API</a>
|
55
57
|
|
56
58
|
<li><a href="README_md.html#label-Self+Promotion">Self Promotion</a>
|
57
59
|
|
@@ -130,6 +132,16 @@
|
|
130
132
|
—
|
131
133
|
<span class="container">Spoonerize::Bumper</span>
|
132
134
|
|
135
|
+
<li class="method">
|
136
|
+
<a href="Spoonerize/Spoonerism.html#method-i-config_file-3D">#config_file=</a>
|
137
|
+
—
|
138
|
+
<span class="container">Spoonerize::Spoonerism</span>
|
139
|
+
|
140
|
+
<li class="method">
|
141
|
+
<a href="Spoonerize/Spoonerism.html#method-i-config_file_loaded-3F">#config_file_loaded?</a>
|
142
|
+
—
|
143
|
+
<span class="container">Spoonerize::Spoonerism</span>
|
144
|
+
|
133
145
|
<li class="method">
|
134
146
|
<a href="Spoonerize/Log.html#method-i-contents">#contents</a>
|
135
147
|
—
|
@@ -150,6 +162,11 @@
|
|
150
162
|
—
|
151
163
|
<span class="container">Spoonerize::Spoonerism</span>
|
152
164
|
|
165
|
+
<li class="method">
|
166
|
+
<a href="Spoonerize/Spoonerism.html#method-i-load_config_file">#load_config_file</a>
|
167
|
+
—
|
168
|
+
<span class="container">Spoonerize::Spoonerism</span>
|
169
|
+
|
153
170
|
<li class="method">
|
154
171
|
<a href="Spoonerize/Cli.html#method-i-longest_word_length">#longest_word_length</a>
|
155
172
|
—
|
@@ -176,14 +193,14 @@
|
|
176
193
|
<span class="container">Spoonerize::Cli</span>
|
177
194
|
|
178
195
|
<li class="method">
|
179
|
-
<a href="Spoonerize/
|
196
|
+
<a href="Spoonerize/Bumper.html#method-i-reverse-3F">#reverse?</a>
|
180
197
|
—
|
181
|
-
<span class="container">Spoonerize::
|
198
|
+
<span class="container">Spoonerize::Bumper</span>
|
182
199
|
|
183
200
|
<li class="method">
|
184
|
-
<a href="Spoonerize/
|
201
|
+
<a href="Spoonerize/Spoonerism.html#method-i-reverse-3F">#reverse?</a>
|
185
202
|
—
|
186
|
-
<span class="container">Spoonerize::
|
203
|
+
<span class="container">Spoonerize::Spoonerism</span>
|
187
204
|
|
188
205
|
<li class="method">
|
189
206
|
<a href="Spoonerize/Spoonerism.html#method-i-save">#save</a>
|
data/lib/config/lazy_words.yml
CHANGED
data/lib/spoonerize/cli.rb
CHANGED
@@ -14,7 +14,7 @@ module Spoonerize
|
|
14
14
|
File.expand_path(File.join(ENV['HOME'], '.spoonerize.yml')).freeze
|
15
15
|
|
16
16
|
##
|
17
|
-
# Creates an instance of +
|
17
|
+
# Creates an instance of +Spoonerism+ and runs what the user requested.
|
18
18
|
#
|
19
19
|
# @param [Array] options
|
20
20
|
def self.execute(options = [])
|
@@ -66,7 +66,8 @@ module Spoonerize
|
|
66
66
|
#
|
67
67
|
# @return [Spoonerize::Spoonerism]
|
68
68
|
def spoonerism
|
69
|
-
|
69
|
+
pf = File.file?(PREFERENCE_FILE) ? PREFERENCE_FILE : nil
|
70
|
+
@spoonerism ||= Spoonerism.new(options, pf) do |s|
|
70
71
|
preferences.each { |k, v| s.send("#{k}=", v) }
|
71
72
|
end
|
72
73
|
end
|
@@ -151,8 +152,7 @@ module Spoonerize
|
|
151
152
|
end
|
152
153
|
end.parse!(options)
|
153
154
|
|
154
|
-
|
155
|
-
.merge(prefs)
|
155
|
+
prefs
|
156
156
|
end
|
157
157
|
end
|
158
158
|
end
|
@@ -1,166 +1,235 @@
|
|
1
1
|
module Spoonerize
|
2
|
-
##
|
3
|
-
# The main word-flipper.
|
4
|
-
class Spoonerism
|
5
|
-
|
6
|
-
##
|
7
|
-
# The words originally passed at initialization.
|
8
|
-
#
|
9
|
-
# @return [Array]
|
10
|
-
attr_reader :words
|
11
|
-
|
12
|
-
##
|
13
|
-
# This boolean determines if flipping should be performed lazily.
|
14
|
-
#
|
15
|
-
# @param [Boolean] true if should be lazy.
|
16
|
-
#
|
17
|
-
# @return [Boolean]
|
18
|
-
attr_writer :lazy
|
19
|
-
|
20
|
-
##
|
21
|
-
# This boolean determines if flipping should be reversed.
|
22
|
-
#
|
23
|
-
# @param [Boolean] true if should be reversed.
|
24
|
-
#
|
25
|
-
# @return [Boolean]
|
26
|
-
attr_writer :reverse
|
27
|
-
|
28
|
-
##
|
29
|
-
# The full path to the log file.
|
30
|
-
#
|
31
|
-
# @param [String] file
|
32
|
-
#
|
33
|
-
# @return [String]
|
34
|
-
attr_accessor :logfile_name
|
35
|
-
|
36
|
-
##
|
37
|
-
# The words that are to be excluded.
|
38
|
-
#
|
39
|
-
# @param [Array] words
|
40
|
-
#
|
41
|
-
# @return [Array]
|
42
|
-
attr_accessor :excluded_words
|
43
|
-
|
44
|
-
##
|
45
|
-
# Initialize instance and raise if there aren't enough words to flip.
|
46
|
-
#
|
47
|
-
# @param [Array] words
|
48
|
-
def initialize(words)
|
49
|
-
@excluded_words = []
|
50
|
-
@words = words.map(&:downcase)
|
51
|
-
@lazy = false
|
52
|
-
@reverse = false
|
53
|
-
@logfile_name = File.expand_path(
|
54
|
-
File.join(ENV['HOME'], '.cache', 'spoonerize', 'spoonerize.csv')
|
55
|
-
)
|
56
|
-
yield self if block_given?
|
57
|
-
end
|
58
|
-
|
59
|
-
##
|
60
|
-
# Iterates through words array, and maps its elements to the output of
|
61
|
-
# flip_words. Returns results as an array.
|
62
|
-
def spoonerize
|
63
|
-
raise JakPibError, 'Not enough words to flip' unless enough_flippable_words?
|
64
|
-
words.map.with_index { |word, idx| flip_words(word, idx) }
|
65
|
-
end
|
66
|
-
|
67
|
-
##
|
68
|
-
# Returns spoonerize array as a joined string.
|
69
|
-
def to_s
|
70
|
-
spoonerize.join(' ')
|
71
|
-
end
|
72
|
-
|
73
|
-
##
|
74
|
-
# Returns hash of the original words mapped to their flipped counterparts.
|
75
|
-
def to_h
|
76
|
-
Hash[words.zip(spoonerize)]
|
77
|
-
end
|
78
|
-
|
79
|
-
##
|
80
|
-
# Same as to_h, but as json.
|
81
|
-
def to_json
|
82
|
-
to_h.to_json
|
83
|
-
end
|
84
|
-
|
85
|
-
##
|
86
|
-
# Returns true if there are more than one non-excluded word to flip
|
87
|
-
def enough_flippable_words?
|
88
|
-
(words - all_excluded_words).size > 1
|
89
|
-
end
|
90
|
-
|
91
2
|
##
|
92
|
-
#
|
93
|
-
|
94
|
-
|
3
|
+
# The main word-flipper.
|
4
|
+
class Spoonerism
|
5
|
+
|
6
|
+
##
|
7
|
+
# The words originally passed at initialization.
|
8
|
+
#
|
9
|
+
# @return [Array]
|
10
|
+
attr_reader :words
|
11
|
+
|
12
|
+
##
|
13
|
+
# This boolean determines if flipping should be performed lazily.
|
14
|
+
#
|
15
|
+
# @param [Boolean] true if should be lazy.
|
16
|
+
#
|
17
|
+
# @return [Boolean]
|
18
|
+
attr_writer :lazy
|
19
|
+
|
20
|
+
##
|
21
|
+
# This boolean determines if flipping should be reversed.
|
22
|
+
#
|
23
|
+
# @param [Boolean] true if should be reversed.
|
24
|
+
#
|
25
|
+
# @return [Boolean]
|
26
|
+
attr_writer :reverse
|
27
|
+
|
28
|
+
##
|
29
|
+
# The full path to the log file.
|
30
|
+
#
|
31
|
+
# @param [String] file
|
32
|
+
#
|
33
|
+
# @return [String]
|
34
|
+
attr_accessor :logfile_name
|
35
|
+
|
36
|
+
##
|
37
|
+
# The words that are to be excluded.
|
38
|
+
#
|
39
|
+
# @param [Array] words
|
40
|
+
#
|
41
|
+
# @return [Array]
|
42
|
+
attr_accessor :excluded_words
|
43
|
+
|
44
|
+
##
|
45
|
+
# The configuration file. Default is +nil+. If set to a string, and the file
|
46
|
+
# exists, it is used to set options.
|
47
|
+
#
|
48
|
+
# @return [String] file path
|
49
|
+
attr_reader :config_file
|
50
|
+
|
51
|
+
##
|
52
|
+
# The options from +config_file+ as a hash.
|
53
|
+
#
|
54
|
+
# @return [Hash] Options from +config_file+
|
55
|
+
attr_reader :config
|
56
|
+
|
57
|
+
##
|
58
|
+
# Initialize instance. You can also use the +config_file+ either by passing
|
59
|
+
# it at initialization, or via the setter. The config file will be
|
60
|
+
# automatically loaded if passed at initialization, before the instance is
|
61
|
+
# yielded so you can still change the values via the block. If set via the
|
62
|
+
# setter, you must call `#load_config_file`.
|
63
|
+
#
|
64
|
+
# @param [Array] words
|
65
|
+
#
|
66
|
+
# @param [String] config_file
|
67
|
+
#
|
68
|
+
# @example
|
69
|
+
# # Config file would be automatically loaded before block is executed.
|
70
|
+
# s = Spoonerise::Spoonerism.new(%w[not too shabby], '~/.spoonerize.yml') do |sp|
|
71
|
+
# sp.reverse = true # Would override setting from config file
|
72
|
+
# end
|
73
|
+
# # Config file would need to be manually loaded.
|
74
|
+
# s = Spoonerise::Spoonerism.new(%w[not too shabby]) do |sp|
|
75
|
+
# sp.config_file = '~/.spoonerize.yml'
|
76
|
+
# sp.reverse = true
|
77
|
+
# end
|
78
|
+
# s.load_config_file # Would override setting from initialization
|
79
|
+
|
80
|
+
def initialize(words, config_file = nil)
|
81
|
+
@config = {}
|
82
|
+
@excluded_words = []
|
83
|
+
@words = words.map(&:downcase)
|
84
|
+
@lazy = false
|
85
|
+
@reverse = false
|
86
|
+
@config_file = config_file && File.expand_path(config_file)
|
87
|
+
@config_file_loaded = false
|
88
|
+
@logfile_name = File.expand_path(
|
89
|
+
File.join(ENV['HOME'], '.cache', 'spoonerize', 'spoonerize.csv')
|
90
|
+
)
|
91
|
+
|
92
|
+
load_config_file if config_file
|
93
|
+
|
94
|
+
yield self if block_given?
|
95
|
+
end
|
96
|
+
|
97
|
+
##
|
98
|
+
# Iterates through words array, and maps its elements to the output of
|
99
|
+
# flip_words. Returns results as an array.
|
100
|
+
def spoonerize
|
101
|
+
raise JakPibError, 'Not enough words to flip' unless enough_flippable_words?
|
102
|
+
words.map.with_index { |word, idx| flip_words(word, idx) }
|
103
|
+
end
|
104
|
+
|
105
|
+
##
|
106
|
+
# Returns spoonerize array as a joined string.
|
107
|
+
def to_s
|
108
|
+
spoonerize.join(' ')
|
109
|
+
end
|
110
|
+
|
111
|
+
##
|
112
|
+
# Returns hash of the original words mapped to their flipped counterparts.
|
113
|
+
def to_h
|
114
|
+
Hash[words.zip(spoonerize)]
|
115
|
+
end
|
116
|
+
|
117
|
+
##
|
118
|
+
# Same as to_h, but as json.
|
119
|
+
def to_json
|
120
|
+
to_h.to_json
|
121
|
+
end
|
122
|
+
|
123
|
+
##
|
124
|
+
# Has a config file been loaded?
|
125
|
+
#
|
126
|
+
# @return [Boolean]
|
127
|
+
def config_file_loaded?
|
128
|
+
@config_file_loaded
|
129
|
+
end
|
130
|
+
|
131
|
+
##
|
132
|
+
# Returns true if there are more than one non-excluded word to flip
|
133
|
+
def enough_flippable_words?
|
134
|
+
(words - all_excluded_words).size > 1
|
135
|
+
end
|
136
|
+
|
137
|
+
##
|
138
|
+
# Should the lazy words be excluded?
|
139
|
+
def lazy?
|
140
|
+
@lazy
|
141
|
+
end
|
142
|
+
|
143
|
+
##
|
144
|
+
# Should the words flip the other direction?
|
145
|
+
def reverse?
|
146
|
+
@reverse
|
147
|
+
end
|
148
|
+
|
149
|
+
##
|
150
|
+
# Saves the flipped words to the log file, along with the options
|
151
|
+
def save
|
152
|
+
log.write([words.join(' '), to_s, options.join(', ')])
|
153
|
+
end
|
154
|
+
|
155
|
+
##
|
156
|
+
# Returns an array of words to exclude by combining three arrays:
|
157
|
+
# * Any word in the passed arguments that's only one character
|
158
|
+
# * Any user-passed words, stored in +excluded_words+
|
159
|
+
# * If lazy-mode, the LAZY_WORDS from yaml file are added
|
160
|
+
def all_excluded_words
|
161
|
+
(excluded_words + (lazy? ? LAZY_WORDS : [])).map(&:downcase)
|
162
|
+
end
|
163
|
+
|
164
|
+
##
|
165
|
+
# Setter for +config_file+. Must be expanded in case the user uses `~` for
|
166
|
+
# home.
|
167
|
+
#
|
168
|
+
# @param [String] file
|
169
|
+
#
|
170
|
+
# @return [String]
|
171
|
+
def config_file=(config_file)
|
172
|
+
@config_file = File.expand_path(config_file)
|
173
|
+
end
|
174
|
+
|
175
|
+
##
|
176
|
+
# Loads the config file
|
177
|
+
#
|
178
|
+
# @return [Hash] The config options
|
179
|
+
def load_config_file
|
180
|
+
raise 'No config file set' if config_file.nil?
|
181
|
+
raise "File #{config_file} does not exist" unless File.file?(config_file)
|
182
|
+
@config = YAML::load_file(config_file)
|
183
|
+
@config_file_loaded = true
|
184
|
+
@config.each { |k, v| send("#{k}=", v) }
|
185
|
+
end
|
186
|
+
|
187
|
+
private
|
188
|
+
|
189
|
+
##
|
190
|
+
# Main flipping method. Creates the replacement word from the next
|
191
|
+
# non-excluded word's leading syllables, and the current word's first vowels
|
192
|
+
# through the end of the word.
|
193
|
+
def flip_words(word, idx) # :nodoc:
|
194
|
+
return word if excluded?(idx)
|
195
|
+
bumper = Bumper.new(idx, words.size, reverse?)
|
196
|
+
bumper.bump until !excluded?(bumper.value)
|
197
|
+
words[bumper.value].match(consonants).to_s + word.match(vowels).to_s
|
198
|
+
end
|
199
|
+
|
200
|
+
##
|
201
|
+
# Returns true if word[index] is in the excluded_words array
|
202
|
+
def excluded?(index) # :nodoc:
|
203
|
+
all_excluded_words.include?(words[index])
|
204
|
+
end
|
205
|
+
|
206
|
+
##
|
207
|
+
# Returns regex to match first vowels through the rest of the word
|
208
|
+
def vowels # :nodoc:
|
209
|
+
/((?<!q)u|[aeio]|(?<=[bcdfghjklmnprstvwxz])y).*$/
|
210
|
+
end
|
211
|
+
|
212
|
+
##
|
213
|
+
# Returns regex to match leading consonants
|
214
|
+
def consonants # :nodoc:
|
215
|
+
/^(y|[bcdfghjklmnprstvwxz]+|qu)/
|
216
|
+
end
|
217
|
+
|
218
|
+
##
|
219
|
+
# Creates and memoizes instance of the log file.
|
220
|
+
def log # :nodoc:
|
221
|
+
@log ||= Spoonerize::Log.new(logfile_name)
|
222
|
+
end
|
223
|
+
|
224
|
+
##
|
225
|
+
# the options as a string
|
226
|
+
def options # :nodoc:
|
227
|
+
o = []
|
228
|
+
o << 'Lazy' if lazy?
|
229
|
+
o << 'Reverse' if reverse?
|
230
|
+
o << "Exclude [#{all_excluded_words.join(', ')}]" if excluded_words.any?
|
231
|
+
o << 'No Options' if o.empty?
|
232
|
+
o
|
233
|
+
end
|
95
234
|
end
|
96
|
-
|
97
|
-
##
|
98
|
-
# Should the words flip the other direction?
|
99
|
-
def reverse?
|
100
|
-
@reverse
|
101
|
-
end
|
102
|
-
|
103
|
-
##
|
104
|
-
# Saves the flipped words to the log file, along with the options
|
105
|
-
def save
|
106
|
-
log.write([words.join(' '), to_s, options.join(', ')])
|
107
|
-
end
|
108
|
-
|
109
|
-
##
|
110
|
-
# Returns an array of words to exclude by combining three arrays:
|
111
|
-
# * Any word in the passed arguments that's only one character
|
112
|
-
# * Any user-passed words, stored in +excluded_words+
|
113
|
-
# * If lazy-mode, the LAZY_WORDS from yaml file are added
|
114
|
-
def all_excluded_words
|
115
|
-
(excluded_words + (lazy? ? LAZY_WORDS : [])).map(&:downcase)
|
116
|
-
end
|
117
|
-
|
118
|
-
private
|
119
|
-
|
120
|
-
##
|
121
|
-
# Main flipping method. Creates the replacement word from the next
|
122
|
-
# non-excluded word's leading syllables, and the current word's first vowels
|
123
|
-
# through the end of the word.
|
124
|
-
def flip_words(word, idx) # :nodoc:
|
125
|
-
return word if excluded?(idx)
|
126
|
-
bumper = Bumper.new(idx, words.size, reverse?)
|
127
|
-
bumper.bump until !excluded?(bumper.value)
|
128
|
-
words[bumper.value].match(consonants).to_s + word.match(vowels).to_s
|
129
|
-
end
|
130
|
-
|
131
|
-
##
|
132
|
-
# Returns true if word[index] is in the excluded_words array
|
133
|
-
def excluded?(index) # :nodoc:
|
134
|
-
all_excluded_words.include?(words[index])
|
135
|
-
end
|
136
|
-
|
137
|
-
##
|
138
|
-
# Returns regex to match first vowels through the rest of the word
|
139
|
-
def vowels # :nodoc:
|
140
|
-
/((?<!q)u|[aeio]|(?<=[bcdfghjklmnprstvwxz])y).*$/
|
141
|
-
end
|
142
|
-
|
143
|
-
##
|
144
|
-
# Returns regex to match leading consonants
|
145
|
-
def consonants # :nodoc:
|
146
|
-
/^(y|[bcdfghjklmnprstvwxz]+|qu)/
|
147
|
-
end
|
148
|
-
|
149
|
-
##
|
150
|
-
# Creates and memoizes instance of the log file.
|
151
|
-
def log # :nodoc:
|
152
|
-
@log ||= Spoonerize::Log.new(logfile_name)
|
153
|
-
end
|
154
|
-
|
155
|
-
##
|
156
|
-
# the options as a string
|
157
|
-
def options # :nodoc:
|
158
|
-
o = []
|
159
|
-
o << 'Lazy' if lazy?
|
160
|
-
o << 'Reverse' if reverse?
|
161
|
-
o << 'Exclude [%s]' % [all_excluded_words.join(', ')] if excluded_words.any?
|
162
|
-
o << 'No Options' if o.empty?
|
163
|
-
o
|
164
|
-
end
|
165
|
-
end
|
166
235
|
end
|