spoonerize 0.2.0 → 1.0.0
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +48 -1
- data/README.md +36 -17
- data/Rakefile +1 -1
- data/lib/spoonerize/cli.rb +12 -9
- data/lib/spoonerize/config.rb +32 -0
- data/lib/spoonerize/spoonerism.rb +139 -24
- data/lib/spoonerize/version.rb +2 -2
- data/lib/spoonerize.rb +1 -1
- data/spoonerize.gemspec +1 -0
- metadata +15 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1b4c993b75b971449d8795c0666e4645bee48ff903afaea84463025da44ffdbf
|
|
4
|
+
data.tar.gz: b57070d3e1dc670ef4cdf17f9657c8759828e86a039571d305a6d6716aaa5b65
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ccf19838d1a10609dddbd2da4cfe8286c548b9bc91e2b957ee592120225305c93a166da7ae10c34ead80a402f8cb767fbb192162fade18afc046298ff3d5dd1c
|
|
7
|
+
data.tar.gz: 3420c7dc81ea682e3388b9f9097a6c538199cbb38e2f5179e3a5f68f8200b278674da04397df05e14a259ad6ba5878daf3b63390f244a3988c3678f08e8b85a3
|
data/Gemfile.lock
CHANGED
|
@@ -1,28 +1,74 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
spoonerize (0.
|
|
4
|
+
spoonerize (1.0.0)
|
|
5
5
|
csv
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
+
ast (2.4.3)
|
|
10
11
|
csv (3.3.5)
|
|
11
12
|
date (3.5.1)
|
|
12
13
|
erb (6.0.4)
|
|
14
|
+
json (2.20.0)
|
|
15
|
+
language_server-protocol (3.17.0.5)
|
|
16
|
+
lint_roller (1.1.0)
|
|
17
|
+
parallel (1.28.0)
|
|
18
|
+
parser (3.3.11.1)
|
|
19
|
+
ast (~> 2.4.1)
|
|
20
|
+
racc
|
|
13
21
|
power_assert (3.0.1)
|
|
22
|
+
prism (1.9.0)
|
|
14
23
|
psych (5.4.0)
|
|
15
24
|
date
|
|
16
25
|
stringio
|
|
26
|
+
racc (1.8.1)
|
|
27
|
+
rainbow (3.1.1)
|
|
17
28
|
rake (13.4.2)
|
|
18
29
|
rdoc (7.2.0)
|
|
19
30
|
erb
|
|
20
31
|
psych (>= 4.0.0)
|
|
21
32
|
tsort
|
|
33
|
+
regexp_parser (2.12.0)
|
|
34
|
+
rubocop (1.84.2)
|
|
35
|
+
json (~> 2.3)
|
|
36
|
+
language_server-protocol (~> 3.17.0.2)
|
|
37
|
+
lint_roller (~> 1.1.0)
|
|
38
|
+
parallel (~> 1.10)
|
|
39
|
+
parser (>= 3.3.0.2)
|
|
40
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
41
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
|
42
|
+
rubocop-ast (>= 1.49.0, < 2.0)
|
|
43
|
+
ruby-progressbar (~> 1.7)
|
|
44
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
|
45
|
+
rubocop-ast (1.49.1)
|
|
46
|
+
parser (>= 3.3.7.2)
|
|
47
|
+
prism (~> 1.7)
|
|
48
|
+
rubocop-performance (1.26.1)
|
|
49
|
+
lint_roller (~> 1.1)
|
|
50
|
+
rubocop (>= 1.75.0, < 2.0)
|
|
51
|
+
rubocop-ast (>= 1.47.1, < 2.0)
|
|
52
|
+
ruby-progressbar (1.13.0)
|
|
53
|
+
standard (1.54.0)
|
|
54
|
+
language_server-protocol (~> 3.17.0.2)
|
|
55
|
+
lint_roller (~> 1.0)
|
|
56
|
+
rubocop (~> 1.84.0)
|
|
57
|
+
standard-custom (~> 1.0.0)
|
|
58
|
+
standard-performance (~> 1.8)
|
|
59
|
+
standard-custom (1.0.2)
|
|
60
|
+
lint_roller (~> 1.0)
|
|
61
|
+
rubocop (~> 1.50)
|
|
62
|
+
standard-performance (1.9.0)
|
|
63
|
+
lint_roller (~> 1.1)
|
|
64
|
+
rubocop-performance (~> 1.26.0)
|
|
22
65
|
stringio (3.2.0)
|
|
23
66
|
test-unit (3.7.8)
|
|
24
67
|
power_assert
|
|
25
68
|
tsort (0.2.0)
|
|
69
|
+
unicode-display_width (3.2.0)
|
|
70
|
+
unicode-emoji (~> 4.1)
|
|
71
|
+
unicode-emoji (4.2.0)
|
|
26
72
|
|
|
27
73
|
PLATFORMS
|
|
28
74
|
arm64-darwin-25
|
|
@@ -33,6 +79,7 @@ DEPENDENCIES
|
|
|
33
79
|
rake (~> 13.0, >= 13.0.1)
|
|
34
80
|
rdoc
|
|
35
81
|
spoonerize!
|
|
82
|
+
standard (= 1.54.0)
|
|
36
83
|
test-unit (~> 3.3, >= 3.3.5)
|
|
37
84
|
|
|
38
85
|
BUNDLED WITH
|
data/README.md
CHANGED
|
@@ -26,6 +26,8 @@ consonants, but will still lose its own if it has any.
|
|
|
26
26
|
- If the word to pull from is excluded, that word is skipped, and you pull the
|
|
27
27
|
leading consonants from the next non-excluded word.
|
|
28
28
|
- "Q" and "U" should stay together (like "queen").
|
|
29
|
+
- "Y" is treated like a leading consonant by itself or before a vowel sound
|
|
30
|
+
(like "yellow"), but like a leading vowel before a consonant (like "yttrium").
|
|
29
31
|
- A lot of the time, the words won't look how they're supposed to sound, as you
|
|
30
32
|
go by how the word *used* to sound, not how it's spelled. For instance,
|
|
31
33
|
`$ spoonerize two new cuties` becomes "no cew twuties", but it would be
|
|
@@ -40,7 +42,7 @@ Just install the gem!
|
|
|
40
42
|
gem install spoonerize
|
|
41
43
|
```
|
|
42
44
|
|
|
43
|
-
If you don't have permission on your system to install
|
|
45
|
+
If you don't have permission on your system to install Ruby or gems, I recommend
|
|
44
46
|
using
|
|
45
47
|
[rbenv](http://www.rubyinside.com/rbenv-a-simple-new-ruby-version-management-tool-5302.html),
|
|
46
48
|
or you can try the manual methods below.
|
|
@@ -82,10 +84,12 @@ get the results. For example:
|
|
|
82
84
|
|
|
83
85
|
```
|
|
84
86
|
$ spoonerize -s not too shabby
|
|
85
|
-
|
|
87
|
+
tot shoo nabby
|
|
88
|
+
Saving...
|
|
86
89
|
|
|
87
90
|
$ spoonerize -rs not too shabby
|
|
88
|
-
|
|
91
|
+
shot noo tabby
|
|
92
|
+
Saving...
|
|
89
93
|
|
|
90
94
|
$ spoonerize -p
|
|
91
95
|
not too shabby | tot shoo nabby | No Options
|
|
@@ -97,10 +101,11 @@ Here is a list of all available options:
|
|
|
97
101
|
```
|
|
98
102
|
-r, --[no-]reverse Reverse flipping
|
|
99
103
|
-l, --[no-]lazy Skip small words
|
|
104
|
+
-c, --[no-]consonants-only Only flip consonant-starting words
|
|
100
105
|
-m, --[no-]map Print words mapping
|
|
101
|
-
-p, --[no-]print
|
|
106
|
+
-p, --[no-]print-log Print all entries in the log
|
|
102
107
|
-s, --[no-]save Save results in log
|
|
103
|
-
--exclude=
|
|
108
|
+
--exclude=WORD Words to skip
|
|
104
109
|
```
|
|
105
110
|
|
|
106
111
|
### Config File
|
|
@@ -112,6 +117,7 @@ file can still be overridden at runtime by executable flags.
|
|
|
112
117
|
Spoonerize.configure do |config|
|
|
113
118
|
config.excluded_words = []
|
|
114
119
|
config.lazy = false
|
|
120
|
+
config.consonants_only = false
|
|
115
121
|
config.reverse = false
|
|
116
122
|
config.logfile_name = File.expand_path("~/.cache/spoonerize/spoonerize.csv")
|
|
117
123
|
end
|
|
@@ -122,50 +128,63 @@ Because the file is Ruby, you can set only the values you want to change.
|
|
|
122
128
|
## API
|
|
123
129
|
The API is [fully
|
|
124
130
|
documented](https://evanthegrayt.github.io/spoonerize/), but below
|
|
125
|
-
are some quick examples of how you could use this in your
|
|
131
|
+
are some quick examples of how you could use this in your Ruby code.
|
|
126
132
|
|
|
127
133
|
```ruby
|
|
128
134
|
require 'spoonerize'
|
|
129
135
|
|
|
130
|
-
spoonerism = Spoonerize::Spoonerism.new(
|
|
136
|
+
spoonerism = Spoonerize::Spoonerism.new("not", "too", "shabby")
|
|
131
137
|
|
|
132
138
|
spoonerism.to_s
|
|
133
139
|
# => tot shoo nabby
|
|
134
140
|
|
|
135
|
-
Spoonerize.
|
|
136
|
-
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
spoonerism.to_s
|
|
141
|
+
reversed = Spoonerize::Spoonerism.new("not", "too", "shabby", reverse: true)
|
|
142
|
+
reversed.to_s
|
|
140
143
|
# => shot noo tabby
|
|
141
144
|
|
|
142
145
|
Spoonerize.configure do |config|
|
|
143
146
|
config.logfile_name = File.expand_path("~/.cache/spoonerize/spoonerize.csv")
|
|
144
147
|
end
|
|
145
|
-
|
|
148
|
+
Spoonerize::Spoonerism.new("not", "too", "shabby").save
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
To leave vowel-starting words alone, enable consonants-only mode:
|
|
152
|
+
|
|
153
|
+
```ruby
|
|
154
|
+
Spoonerize::Spoonerism.new("turn", "up", "son", consonants_only: true).to_s
|
|
155
|
+
# => surn up ton
|
|
146
156
|
```
|
|
147
157
|
|
|
148
|
-
You can also configure
|
|
158
|
+
You can also configure global defaults before creating a spoonerism:
|
|
149
159
|
|
|
150
160
|
```ruby
|
|
151
161
|
Spoonerize.configure do |config|
|
|
152
162
|
config.reverse = true
|
|
153
163
|
end
|
|
154
164
|
|
|
155
|
-
s = Spoonerize::Spoonerism.new(
|
|
165
|
+
s = Spoonerize::Spoonerism.new("not", "too", "shabby")
|
|
156
166
|
s.spoonerize
|
|
157
167
|
# => shot noo tabby
|
|
158
168
|
```
|
|
159
169
|
|
|
170
|
+
Options passed directly to `Spoonerize::Spoonerism.new` only apply to that
|
|
171
|
+
instance.
|
|
172
|
+
|
|
173
|
+
Passing words as an array is deprecated and will be removed in Spoonerize 1.0:
|
|
174
|
+
|
|
175
|
+
```ruby
|
|
176
|
+
Spoonerize::Spoonerism.new(%w[not too shabby])
|
|
177
|
+
```
|
|
178
|
+
|
|
160
179
|
Or load a config file manually:
|
|
161
180
|
|
|
162
181
|
```ruby
|
|
163
182
|
Spoonerize.load_config_file("~/.spoonerizerc")
|
|
164
|
-
s = Spoonerize::Spoonerism.new(
|
|
183
|
+
s = Spoonerize::Spoonerism.new("not", "too", "shabby")
|
|
165
184
|
```
|
|
166
185
|
|
|
167
186
|
## Self Promotion
|
|
168
187
|
I do these projects for fun, and I enjoy knowing that they're helpful to people.
|
|
169
188
|
Consider starring [the repository](https://github.com/evanthegrayt/spoonerize)
|
|
170
189
|
if you like it! If you love it, follow me [on
|
|
171
|
-
|
|
190
|
+
GitHub](https://github.com/evanthegrayt)!
|
data/Rakefile
CHANGED
data/lib/spoonerize/cli.rb
CHANGED
|
@@ -40,10 +40,10 @@ module Spoonerize
|
|
|
40
40
|
attr_reader :options
|
|
41
41
|
|
|
42
42
|
##
|
|
43
|
-
#
|
|
43
|
+
# Overrides after reading config file and parsing ARGV.
|
|
44
44
|
#
|
|
45
|
-
# @return [
|
|
46
|
-
attr_reader :
|
|
45
|
+
# @return [Hash]
|
|
46
|
+
attr_reader :overrides
|
|
47
47
|
|
|
48
48
|
##
|
|
49
49
|
# Create instance of +Cli+
|
|
@@ -57,7 +57,7 @@ module Spoonerize
|
|
|
57
57
|
@save = false
|
|
58
58
|
@print_log = false
|
|
59
59
|
@options = options
|
|
60
|
-
@
|
|
60
|
+
@overrides = get_overrides
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
##
|
|
@@ -65,7 +65,7 @@ module Spoonerize
|
|
|
65
65
|
#
|
|
66
66
|
# @return [Spoonerize::Spoonerism]
|
|
67
67
|
def spoonerism
|
|
68
|
-
@spoonerism ||= Spoonerism.new(options)
|
|
68
|
+
@spoonerism ||= Spoonerism.new(*options, **overrides)
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
##
|
|
@@ -124,15 +124,18 @@ module Spoonerize
|
|
|
124
124
|
|
|
125
125
|
##
|
|
126
126
|
# Read in args and set options
|
|
127
|
-
def
|
|
127
|
+
def get_overrides # :nodoc:
|
|
128
128
|
{}.tap do |prefs|
|
|
129
129
|
OptionParser.new do |o|
|
|
130
130
|
o.version = ::Spoonerize::Version.to_s
|
|
131
131
|
o.on("-r", "--[no-]reverse", "Reverse flipping") do |v|
|
|
132
|
-
|
|
132
|
+
prefs[:reverse] = v
|
|
133
133
|
end
|
|
134
134
|
o.on("-l", "--[no-]lazy", "Skip small words") do |v|
|
|
135
|
-
|
|
135
|
+
prefs[:lazy] = v
|
|
136
|
+
end
|
|
137
|
+
o.on("-c", "--[no-]consonants-only", "Only flip consonant-starting words") do |v|
|
|
138
|
+
prefs[:consonants_only] = v
|
|
136
139
|
end
|
|
137
140
|
o.on("-m", "--[no-]map", "Print words mapping") do |v|
|
|
138
141
|
@map = v
|
|
@@ -144,7 +147,7 @@ module Spoonerize
|
|
|
144
147
|
@save = v
|
|
145
148
|
end
|
|
146
149
|
o.on("--exclude=WORD", Array, "Words to skip") do |v|
|
|
147
|
-
|
|
150
|
+
prefs[:excluded_words] = v
|
|
148
151
|
end
|
|
149
152
|
end.parse!(options)
|
|
150
153
|
end
|
data/lib/spoonerize/config.rb
CHANGED
|
@@ -20,6 +20,12 @@ module Spoonerize
|
|
|
20
20
|
# @return [Array]
|
|
21
21
|
attr_accessor :excluded_words
|
|
22
22
|
|
|
23
|
+
##
|
|
24
|
+
# When true, only consonant-starting words are eligible to be flipped.
|
|
25
|
+
#
|
|
26
|
+
# @return [Boolean]
|
|
27
|
+
attr_accessor :consonants_only
|
|
28
|
+
|
|
23
29
|
##
|
|
24
30
|
# When true, reverse the order of the flipping. Only makes a difference
|
|
25
31
|
# when there are more than two flip-able words.
|
|
@@ -41,10 +47,36 @@ module Spoonerize
|
|
|
41
47
|
@lazy = false
|
|
42
48
|
@lazy_words = %w[i a an and in of the my your his her him hers to is]
|
|
43
49
|
@excluded_words = []
|
|
50
|
+
@consonants_only = false
|
|
44
51
|
@reverse = false
|
|
45
52
|
@logfile_name = File.expand_path(
|
|
46
53
|
File.join(ENV["HOME"], ".cache", "spoonerize", "spoonerize.csv")
|
|
47
54
|
)
|
|
48
55
|
end
|
|
56
|
+
|
|
57
|
+
##
|
|
58
|
+
# Create a copy of the current config with optional overrides.
|
|
59
|
+
#
|
|
60
|
+
# @return [Spoonerize::Config]
|
|
61
|
+
def with(**overrides)
|
|
62
|
+
self.class.new.tap do |config|
|
|
63
|
+
config.lazy = lazy
|
|
64
|
+
config.lazy_words = lazy_words.dup
|
|
65
|
+
config.excluded_words = excluded_words.dup
|
|
66
|
+
config.consonants_only = consonants_only
|
|
67
|
+
config.reverse = reverse
|
|
68
|
+
config.logfile_name = logfile_name
|
|
69
|
+
|
|
70
|
+
overrides.each do |key, value|
|
|
71
|
+
config.public_send(:"#{key}=", copy_value(value))
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
private
|
|
77
|
+
|
|
78
|
+
def copy_value(value)
|
|
79
|
+
value.is_a?(Array) ? value.dup : value
|
|
80
|
+
end
|
|
49
81
|
end
|
|
50
82
|
end
|
|
@@ -4,20 +4,55 @@ module Spoonerize
|
|
|
4
4
|
##
|
|
5
5
|
# The main word-flipper.
|
|
6
6
|
class Spoonerism
|
|
7
|
+
VOWEL_LETTERS = "aeio"
|
|
8
|
+
CONSONANT_LETTERS = "bcdfghjklmnprstvwxz"
|
|
9
|
+
Y_FOLLOWING_CONSONANTS = "bcdfghjklmnpqrstvwxz"
|
|
10
|
+
|
|
7
11
|
##
|
|
8
12
|
# The words originally passed at initialization.
|
|
9
13
|
#
|
|
10
14
|
# @return [Array]
|
|
11
15
|
attr_reader :words
|
|
12
16
|
|
|
17
|
+
##
|
|
18
|
+
# Configuration values for this spoonerism.
|
|
19
|
+
#
|
|
20
|
+
# @return [Spoonerize::Config]
|
|
21
|
+
attr_reader :config
|
|
22
|
+
|
|
13
23
|
##
|
|
14
24
|
# Initialize instance.
|
|
15
25
|
#
|
|
16
|
-
# @param [Array] words
|
|
26
|
+
# @param [Array<String>] words Words to spoonerize. Passing a single array
|
|
27
|
+
# is deprecated and will be removed in Spoonerize 1.0.
|
|
28
|
+
# @param [Spoonerize::Config] config Base config to copy.
|
|
29
|
+
# @param [Boolean, nil] lazy Override lazy mode for this instance.
|
|
30
|
+
# @param [Array<String>, nil] lazy_words Override lazy words for this instance.
|
|
31
|
+
# @param [Array<String>, nil] excluded_words Override excluded words for this instance.
|
|
32
|
+
# @param [Boolean, nil] consonants_only Override consonants-only mode for this instance.
|
|
33
|
+
# @param [Boolean, nil] reverse Override reverse mode for this instance.
|
|
34
|
+
# @param [String, nil] logfile_name Override the log file path for this instance.
|
|
17
35
|
#
|
|
18
36
|
# @return [Spoonerize::Spoonerism]
|
|
19
|
-
def initialize(
|
|
20
|
-
|
|
37
|
+
def initialize(
|
|
38
|
+
*words,
|
|
39
|
+
config: Spoonerize.config,
|
|
40
|
+
lazy: nil,
|
|
41
|
+
lazy_words: nil,
|
|
42
|
+
excluded_words: nil,
|
|
43
|
+
consonants_only: nil,
|
|
44
|
+
reverse: nil,
|
|
45
|
+
logfile_name: nil
|
|
46
|
+
)
|
|
47
|
+
@words = normalize_words(words).map(&:downcase)
|
|
48
|
+
@config = config.with(**{
|
|
49
|
+
lazy: lazy,
|
|
50
|
+
lazy_words: lazy_words,
|
|
51
|
+
excluded_words: excluded_words,
|
|
52
|
+
consonants_only: consonants_only,
|
|
53
|
+
reverse: reverse,
|
|
54
|
+
logfile_name: logfile_name
|
|
55
|
+
}.reject { |_, value| value.nil? })
|
|
21
56
|
end
|
|
22
57
|
|
|
23
58
|
##
|
|
@@ -60,7 +95,7 @@ module Spoonerize
|
|
|
60
95
|
#
|
|
61
96
|
# @return [Boolean]
|
|
62
97
|
def enough_flippable_words?
|
|
63
|
-
|
|
98
|
+
words.each_index.count { |index| flippable?(index) } > 1
|
|
64
99
|
end
|
|
65
100
|
|
|
66
101
|
##
|
|
@@ -73,27 +108,44 @@ module Spoonerize
|
|
|
73
108
|
|
|
74
109
|
##
|
|
75
110
|
# Array of words to exclude by combining two arrays:
|
|
76
|
-
# * Any user-passed words, stored in +
|
|
111
|
+
# * Any user-passed words, stored in +config.excluded_words+
|
|
77
112
|
# * Any lazy words, if lazy mode is true
|
|
78
113
|
#
|
|
79
114
|
# @return [Array]
|
|
80
115
|
def all_excluded_words
|
|
81
|
-
(
|
|
82
|
-
|
|
116
|
+
(config.excluded_words + (
|
|
117
|
+
config.lazy ? config.lazy_words : []
|
|
83
118
|
)).map(&:downcase)
|
|
84
119
|
end
|
|
85
120
|
|
|
86
121
|
private
|
|
87
122
|
|
|
123
|
+
def normalize_words(words)
|
|
124
|
+
if words.size == 1 && words.first.is_a?(Array)
|
|
125
|
+
warn(
|
|
126
|
+
"Passing words as an array is deprecated and will be removed in Spoonerize 1.0. " \
|
|
127
|
+
"Pass words as positional arguments instead."
|
|
128
|
+
)
|
|
129
|
+
words = words.first
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
unless words.all? { |word| word.is_a?(String) }
|
|
133
|
+
raise ArgumentError, "Words must be strings"
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
words
|
|
137
|
+
end
|
|
138
|
+
|
|
88
139
|
##
|
|
89
140
|
# Main flipping method. Creates the replacement word from the next
|
|
90
|
-
# non-excluded word's leading
|
|
91
|
-
# through the end of the word.
|
|
141
|
+
# non-excluded word's leading consonants, and the current word's first
|
|
142
|
+
# vowel sound through the end of the word.
|
|
92
143
|
def flip_words(word, idx) # :nodoc:
|
|
93
|
-
return word
|
|
94
|
-
|
|
95
|
-
bumper
|
|
96
|
-
|
|
144
|
+
return word unless flippable?(idx)
|
|
145
|
+
|
|
146
|
+
bumper = Bumper.new(idx, words.size, config.reverse)
|
|
147
|
+
bumper.bump until flippable?(bumper.value)
|
|
148
|
+
leading_consonants(words[bumper.value]) + retained_suffix(word)
|
|
97
149
|
end
|
|
98
150
|
|
|
99
151
|
##
|
|
@@ -103,31 +155,94 @@ module Spoonerize
|
|
|
103
155
|
end
|
|
104
156
|
|
|
105
157
|
##
|
|
106
|
-
# Returns
|
|
107
|
-
def
|
|
108
|
-
|
|
158
|
+
# Returns true if word[index] can participate in a spoonerism.
|
|
159
|
+
def flippable?(index) # :nodoc:
|
|
160
|
+
return false if excluded?(index)
|
|
161
|
+
|
|
162
|
+
!config.consonants_only || consonant_sound_start?(words[index])
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
##
|
|
166
|
+
# Returns true when a word starts with a consonant sound.
|
|
167
|
+
def consonant_sound_start?(word) # :nodoc:
|
|
168
|
+
return false if word.empty?
|
|
169
|
+
|
|
170
|
+
!vowel_sound_at?(word, 0)
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
##
|
|
174
|
+
# Returns the consonant group a word contributes to another word.
|
|
175
|
+
def leading_consonants(word) # :nodoc:
|
|
176
|
+
return "qu" if word.start_with?("qu")
|
|
177
|
+
return "y" if initial_y_consonant?(word)
|
|
178
|
+
|
|
179
|
+
index = word.length.times.find do |letter_index|
|
|
180
|
+
!CONSONANT_LETTERS.include?(word[letter_index])
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
index ? word[0...index] : word
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
##
|
|
187
|
+
# Returns the part of a word kept after dropping its leading consonants.
|
|
188
|
+
def retained_suffix(word) # :nodoc:
|
|
189
|
+
index = first_vowel_sound_index(word)
|
|
190
|
+
|
|
191
|
+
index ? word[index..] : ""
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
##
|
|
195
|
+
# Returns the first index where a word starts sounding vowel-like.
|
|
196
|
+
def first_vowel_sound_index(word) # :nodoc:
|
|
197
|
+
word.length.times.find { |index| vowel_sound_at?(word, index) }
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
##
|
|
201
|
+
# Returns true when the letter at index starts a vowel sound.
|
|
202
|
+
def vowel_sound_at?(word, index) # :nodoc:
|
|
203
|
+
letter = word[index]
|
|
204
|
+
|
|
205
|
+
VOWEL_LETTERS.include?(letter) ||
|
|
206
|
+
(letter == "u" && word[index - 1] != "q") ||
|
|
207
|
+
y_vowel_sound_at?(word, index)
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
##
|
|
211
|
+
# Initial y is vowel-like before a consonant; later y is vowel-like after a
|
|
212
|
+
# consonant.
|
|
213
|
+
def y_vowel_sound_at?(word, index) # :nodoc:
|
|
214
|
+
return false unless word[index] == "y"
|
|
215
|
+
|
|
216
|
+
if index.zero?
|
|
217
|
+
next_letter = word[index + 1]
|
|
218
|
+
|
|
219
|
+
next_letter && Y_FOLLOWING_CONSONANTS.include?(next_letter)
|
|
220
|
+
else
|
|
221
|
+
CONSONANT_LETTERS.include?(word[index - 1])
|
|
222
|
+
end
|
|
109
223
|
end
|
|
110
224
|
|
|
111
225
|
##
|
|
112
|
-
#
|
|
113
|
-
def
|
|
114
|
-
|
|
226
|
+
# Initial y is consonant-like by itself or before a vowel sound.
|
|
227
|
+
def initial_y_consonant?(word) # :nodoc:
|
|
228
|
+
word == "y" || (word.start_with?("y") && vowel_sound_at?(word, 1))
|
|
115
229
|
end
|
|
116
230
|
|
|
117
231
|
##
|
|
118
232
|
# Creates and memoizes instance of the log file.
|
|
119
233
|
def log # :nodoc:
|
|
120
|
-
@log ||= Spoonerize::Log.new(
|
|
234
|
+
@log ||= Spoonerize::Log.new(config.logfile_name)
|
|
121
235
|
end
|
|
122
236
|
|
|
123
237
|
##
|
|
124
238
|
# The options that were passed at runtime as a string
|
|
125
239
|
def options # :nodoc:
|
|
126
240
|
[].tap do |o|
|
|
127
|
-
o << "Lazy" if
|
|
128
|
-
o << "
|
|
129
|
-
if
|
|
130
|
-
|
|
241
|
+
o << "Lazy" if config.lazy
|
|
242
|
+
o << "Consonants Only" if config.consonants_only
|
|
243
|
+
o << "Reverse" if config.reverse
|
|
244
|
+
if config.excluded_words.any?
|
|
245
|
+
o << "Exclude [#{config.excluded_words.join(", ")}]"
|
|
131
246
|
end
|
|
132
247
|
o << "No Options" if o.empty?
|
|
133
248
|
end
|
data/lib/spoonerize/version.rb
CHANGED
data/lib/spoonerize.rb
CHANGED
data/spoonerize.gemspec
CHANGED
|
@@ -31,5 +31,6 @@ Gem::Specification.new do |spec|
|
|
|
31
31
|
spec.add_dependency "csv"
|
|
32
32
|
spec.add_development_dependency "rdoc"
|
|
33
33
|
spec.add_development_dependency "rake", "~> 13.0", ">= 13.0.1"
|
|
34
|
+
spec.add_development_dependency "standard", "= 1.54.0"
|
|
34
35
|
spec.add_development_dependency "test-unit", "~> 3.3", ">= 3.3.5"
|
|
35
36
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: spoonerize
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Evan Gray
|
|
@@ -57,6 +57,20 @@ dependencies:
|
|
|
57
57
|
- - ">="
|
|
58
58
|
- !ruby/object:Gem::Version
|
|
59
59
|
version: 13.0.1
|
|
60
|
+
- !ruby/object:Gem::Dependency
|
|
61
|
+
name: standard
|
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
|
63
|
+
requirements:
|
|
64
|
+
- - '='
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: 1.54.0
|
|
67
|
+
type: :development
|
|
68
|
+
prerelease: false
|
|
69
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
70
|
+
requirements:
|
|
71
|
+
- - '='
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: 1.54.0
|
|
60
74
|
- !ruby/object:Gem::Dependency
|
|
61
75
|
name: test-unit
|
|
62
76
|
requirement: !ruby/object:Gem::Requirement
|