wordlist 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/ruby.yml +27 -0
- data/.gitignore +6 -3
- data/ChangeLog.md +45 -1
- data/Gemfile +13 -0
- data/LICENSE.txt +1 -3
- data/README.md +266 -61
- data/Rakefile +7 -32
- data/benchmarks.rb +115 -0
- data/bin/wordlist +4 -7
- data/data/stop_words/ar.txt +104 -0
- data/data/stop_words/bg.txt +259 -0
- data/data/stop_words/bn.txt +363 -0
- data/data/stop_words/ca.txt +126 -0
- data/data/stop_words/cs.txt +138 -0
- data/data/stop_words/da.txt +101 -0
- data/data/stop_words/de.txt +129 -0
- data/data/stop_words/el.txt +79 -0
- data/data/stop_words/en.txt +175 -0
- data/data/stop_words/es.txt +178 -0
- data/data/stop_words/eu.txt +98 -0
- data/data/stop_words/fa.txt +332 -0
- data/data/stop_words/fi.txt +747 -0
- data/data/stop_words/fr.txt +116 -0
- data/data/stop_words/ga.txt +109 -0
- data/data/stop_words/gl.txt +160 -0
- data/data/stop_words/he.txt +499 -0
- data/data/stop_words/hi.txt +97 -0
- data/data/stop_words/hr.txt +179 -0
- data/data/stop_words/hu.txt +35 -0
- data/data/stop_words/hy.txt +45 -0
- data/data/stop_words/id.txt +357 -0
- data/data/stop_words/it.txt +134 -0
- data/data/stop_words/ja.txt +44 -0
- data/data/stop_words/ko.txt +677 -0
- data/data/stop_words/ku.txt +63 -0
- data/data/stop_words/lt.txt +507 -0
- data/data/stop_words/lv.txt +163 -0
- data/data/stop_words/mr.txt +99 -0
- data/data/stop_words/nl.txt +48 -0
- data/data/stop_words/no.txt +172 -0
- data/data/stop_words/pl.txt +138 -0
- data/data/stop_words/pt.txt +147 -0
- data/data/stop_words/ro.txt +281 -0
- data/data/stop_words/ru.txt +421 -0
- data/data/stop_words/sk.txt +173 -0
- data/data/stop_words/sv.txt +386 -0
- data/data/stop_words/th.txt +115 -0
- data/data/stop_words/tr.txt +114 -0
- data/data/stop_words/uk.txt +28 -0
- data/data/stop_words/ur.txt +513 -0
- data/data/stop_words/zh.txt +125 -0
- data/gemspec.yml +4 -10
- data/lib/wordlist/abstract_wordlist.rb +24 -0
- data/lib/wordlist/builder.rb +170 -138
- data/lib/wordlist/cli.rb +458 -0
- data/lib/wordlist/compression/reader.rb +72 -0
- data/lib/wordlist/compression/writer.rb +80 -0
- data/lib/wordlist/exceptions.rb +31 -0
- data/lib/wordlist/file.rb +176 -0
- data/lib/wordlist/format.rb +38 -0
- data/lib/wordlist/lexer/lang.rb +32 -0
- data/lib/wordlist/lexer/stop_words.rb +68 -0
- data/lib/wordlist/lexer.rb +218 -0
- data/lib/wordlist/list_methods.rb +462 -0
- data/lib/wordlist/modifiers/capitalize.rb +45 -0
- data/lib/wordlist/modifiers/downcase.rb +45 -0
- data/lib/wordlist/modifiers/gsub.rb +51 -0
- data/lib/wordlist/modifiers/modifier.rb +44 -0
- data/lib/wordlist/modifiers/mutate.rb +133 -0
- data/lib/wordlist/modifiers/mutate_case.rb +25 -0
- data/lib/wordlist/modifiers/sub.rb +97 -0
- data/lib/wordlist/modifiers/tr.rb +71 -0
- data/lib/wordlist/modifiers/upcase.rb +45 -0
- data/lib/wordlist/modifiers.rb +8 -0
- data/lib/wordlist/operators/binary_operator.rb +38 -0
- data/lib/wordlist/operators/concat.rb +47 -0
- data/lib/wordlist/operators/intersect.rb +55 -0
- data/lib/wordlist/operators/operator.rb +29 -0
- data/lib/wordlist/operators/power.rb +72 -0
- data/lib/wordlist/operators/product.rb +50 -0
- data/lib/wordlist/operators/subtract.rb +54 -0
- data/lib/wordlist/operators/unary_operator.rb +29 -0
- data/lib/wordlist/operators/union.rb +61 -0
- data/lib/wordlist/operators/unique.rb +52 -0
- data/lib/wordlist/operators.rb +7 -0
- data/lib/wordlist/unique_filter.rb +40 -61
- data/lib/wordlist/version.rb +1 -1
- data/lib/wordlist/words.rb +71 -0
- data/lib/wordlist.rb +103 -2
- data/spec/abstract_list_spec.rb +18 -0
- data/spec/builder_spec.rb +220 -76
- data/spec/cli_spec.rb +801 -0
- data/spec/compression/reader_spec.rb +137 -0
- data/spec/compression/writer_spec.rb +194 -0
- data/spec/file_spec.rb +258 -0
- data/spec/fixtures/wordlist.txt +15 -0
- data/spec/fixtures/wordlist.txt.bz2 +0 -0
- data/spec/fixtures/wordlist.txt.gz +0 -0
- data/spec/fixtures/wordlist.txt.xz +0 -0
- data/spec/fixtures/wordlist_with_ambiguous_format +3 -0
- data/spec/fixtures/wordlist_with_comments.txt +19 -0
- data/spec/fixtures/wordlist_with_empty_lines.txt +19 -0
- data/spec/format_spec.rb +50 -0
- data/spec/helpers/text.rb +3 -3
- data/spec/helpers/wordlist.rb +2 -2
- data/spec/lexer/lang_spec.rb +70 -0
- data/spec/lexer/stop_words_spec.rb +77 -0
- data/spec/lexer_spec.rb +652 -0
- data/spec/list_methods_spec.rb +181 -0
- data/spec/modifiers/capitalize_spec.rb +27 -0
- data/spec/modifiers/downcase_spec.rb +27 -0
- data/spec/modifiers/gsub_spec.rb +59 -0
- data/spec/modifiers/modifier_spec.rb +20 -0
- data/spec/modifiers/mutate_case_spec.rb +46 -0
- data/spec/modifiers/mutate_spec.rb +39 -0
- data/spec/modifiers/sub_spec.rb +98 -0
- data/spec/modifiers/tr_spec.rb +46 -0
- data/spec/modifiers/upcase_spec.rb +27 -0
- data/spec/operators/binary_operator_spec.rb +19 -0
- data/spec/operators/concat_spec.rb +26 -0
- data/spec/operators/intersect_spec.rb +37 -0
- data/spec/operators/operator_spec.rb +16 -0
- data/spec/operators/power_spec.rb +57 -0
- data/spec/operators/product_spec.rb +39 -0
- data/spec/operators/subtract_spec.rb +37 -0
- data/spec/operators/union_spec.rb +37 -0
- data/spec/operators/unique_spec.rb +25 -0
- data/spec/spec_helper.rb +2 -1
- data/spec/unique_filter_spec.rb +108 -18
- data/spec/wordlist_spec.rb +55 -3
- data/spec/words_spec.rb +41 -0
- metadata +183 -120
- data/lib/wordlist/builders/website.rb +0 -216
- data/lib/wordlist/builders.rb +0 -1
- data/lib/wordlist/flat_file.rb +0 -47
- data/lib/wordlist/list.rb +0 -162
- data/lib/wordlist/mutator.rb +0 -113
- data/lib/wordlist/parsers.rb +0 -74
- data/lib/wordlist/runners/list.rb +0 -116
- data/lib/wordlist/runners/runner.rb +0 -67
- data/lib/wordlist/runners.rb +0 -2
- data/scripts/benchmark +0 -59
- data/scripts/text/comedy_of_errors.txt +0 -4011
- data/spec/flat_file_spec.rb +0 -25
- data/spec/list_spec.rb +0 -58
- data/spec/mutator_spec.rb +0 -43
- data/spec/parsers_spec.rb +0 -118
@@ -0,0 +1,462 @@
|
|
1
|
+
require 'wordlist/operators'
|
2
|
+
require 'wordlist/modifiers'
|
3
|
+
|
4
|
+
module Wordlist
|
5
|
+
#
|
6
|
+
# List operator and modifier methods.
|
7
|
+
#
|
8
|
+
# @since 1.0.0
|
9
|
+
#
|
10
|
+
module ListMethods
|
11
|
+
#
|
12
|
+
# @group Operators
|
13
|
+
#
|
14
|
+
|
15
|
+
#
|
16
|
+
# Lazily enumerates over the first wordlist, then the second.
|
17
|
+
#
|
18
|
+
# @param [Enumerable] other
|
19
|
+
# The other wordlist to concat.
|
20
|
+
#
|
21
|
+
# @return [Operators::Concat]
|
22
|
+
# The lazily concatenated wordlists.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
# wordlist1 = Wordlist::List["foo", "bar", "baz"]
|
26
|
+
# wordlist2 = Wordlist::List["abc", "xyz"]
|
27
|
+
# (wordlist1 + wordlist2).each do |word|
|
28
|
+
# puts word
|
29
|
+
# end
|
30
|
+
# # foo
|
31
|
+
# # bar
|
32
|
+
# # baz
|
33
|
+
# # abc
|
34
|
+
# # xyz
|
35
|
+
#
|
36
|
+
# @api public
|
37
|
+
#
|
38
|
+
def concat(other)
|
39
|
+
Operators::Concat.new(self,other)
|
40
|
+
end
|
41
|
+
|
42
|
+
alias + concat
|
43
|
+
|
44
|
+
#
|
45
|
+
# Lazily enumerates over every word in the first wordlist, that is not in
|
46
|
+
# the second wordlist.
|
47
|
+
#
|
48
|
+
# @param [Enumerable] other
|
49
|
+
# The other wordlist to subtract.
|
50
|
+
#
|
51
|
+
# @return [Operators::Subtract]
|
52
|
+
# The lazy subtraction of the two wordlists.
|
53
|
+
#
|
54
|
+
# @example
|
55
|
+
# wordlist1 = Wordlist::List["foo", "bar", baz", "qux"]
|
56
|
+
# wordlist2 = Wordlist::List["bar", "qux"]
|
57
|
+
# (wordlist1 - wordlist2).each do |word|
|
58
|
+
# puts word
|
59
|
+
# end
|
60
|
+
# # foo
|
61
|
+
# # baz
|
62
|
+
#
|
63
|
+
# @api public
|
64
|
+
#
|
65
|
+
def subtract(other)
|
66
|
+
Operators::Subtract.new(self,other)
|
67
|
+
end
|
68
|
+
|
69
|
+
alias - subtract
|
70
|
+
|
71
|
+
#
|
72
|
+
# Lazily enumerates over the combination of the words from two wordlists.
|
73
|
+
#
|
74
|
+
# @param [Enumerable] other
|
75
|
+
# The other wordlist to combine with.
|
76
|
+
#
|
77
|
+
# @return [Operators::Product]
|
78
|
+
# The lazy product of the two wordlists.
|
79
|
+
#
|
80
|
+
# @example
|
81
|
+
# wordlist1 = Wordlist::List["foo", "bar"]
|
82
|
+
# wordlist2 = Wordlist::List["ABC", "XYZ"]
|
83
|
+
# (wordlist1 * wordlist2).each do |word|
|
84
|
+
# puts word
|
85
|
+
# end
|
86
|
+
# # fooABC
|
87
|
+
# # fooXYZ
|
88
|
+
# # barABC
|
89
|
+
# # barXYZ
|
90
|
+
#
|
91
|
+
# @api public
|
92
|
+
#
|
93
|
+
def product(other)
|
94
|
+
Operators::Product.new(self,other)
|
95
|
+
end
|
96
|
+
|
97
|
+
alias * product
|
98
|
+
|
99
|
+
#
|
100
|
+
# Lazily enumerates over every combination of words in the wordlist.
|
101
|
+
#
|
102
|
+
# @param [Integer] exponent
|
103
|
+
# The number of times the wordlist will be combined with itself.
|
104
|
+
#
|
105
|
+
# @return [Operators::Power]
|
106
|
+
# The lazy combination of the wordlist.
|
107
|
+
#
|
108
|
+
# @example
|
109
|
+
# wordlist = Wordlist::List["foo", "bar"]
|
110
|
+
# (wordlist ** 3).each do |word|
|
111
|
+
# puts word
|
112
|
+
# end
|
113
|
+
# # foofoofoo
|
114
|
+
# # foofoobar
|
115
|
+
# # foobarfoo
|
116
|
+
# # foobarbar
|
117
|
+
# # barfoofoo
|
118
|
+
# # barfoobar
|
119
|
+
# # barbarfoo
|
120
|
+
# # barbarbar
|
121
|
+
#
|
122
|
+
# @api public
|
123
|
+
#
|
124
|
+
def power(exponent)
|
125
|
+
Operators::Power.new(self,exponent)
|
126
|
+
end
|
127
|
+
|
128
|
+
alias ** power
|
129
|
+
|
130
|
+
#
|
131
|
+
# Lazily enumerates over every word that belongs to both wordlists.
|
132
|
+
#
|
133
|
+
# @param [Enumerable] other
|
134
|
+
# The other wordlist to intersect with.
|
135
|
+
#
|
136
|
+
# @return [Operators::Intersect]
|
137
|
+
# The lazy intersection of the two wordlists.
|
138
|
+
#
|
139
|
+
# @example
|
140
|
+
# wordlist1 = Wordlist::List["foo", "bar", "baz", "qux"]
|
141
|
+
# wordlist2 = Wordlist::List["xyz", "bar", "abc", "qux"]
|
142
|
+
# (wordlist1 & wordlist2).each do |word|
|
143
|
+
# puts word
|
144
|
+
# end
|
145
|
+
# # bar
|
146
|
+
# # qux
|
147
|
+
#
|
148
|
+
# @api public
|
149
|
+
#
|
150
|
+
def intersect(other)
|
151
|
+
Operators::Intersect.new(self,other)
|
152
|
+
end
|
153
|
+
|
154
|
+
alias & intersect
|
155
|
+
|
156
|
+
#
|
157
|
+
# Lazily enumerates over words from both wordlists, filtering out any
|
158
|
+
# duplicates.
|
159
|
+
#
|
160
|
+
# @param [Enumerable] other
|
161
|
+
# The other wordlist to union with.
|
162
|
+
#
|
163
|
+
# @return [Operators::Union]
|
164
|
+
# The lazy union of the two wordlists.
|
165
|
+
#
|
166
|
+
# @example
|
167
|
+
# wordlist1 = Wordlist::List["foo", "bar", "baz", "qux"]
|
168
|
+
# wordlist2 = Wordlist::List["xyz", "bar", "abc", "qux"]
|
169
|
+
# (wordlist1 | wordlist2).each do |word|
|
170
|
+
# puts word
|
171
|
+
# end
|
172
|
+
# # foo
|
173
|
+
# # bar
|
174
|
+
# # baz
|
175
|
+
# # qux
|
176
|
+
# # xyz
|
177
|
+
# # abc
|
178
|
+
#
|
179
|
+
# @api public
|
180
|
+
#
|
181
|
+
def union(other)
|
182
|
+
Operators::Union.new(self,other)
|
183
|
+
end
|
184
|
+
|
185
|
+
alias | union
|
186
|
+
|
187
|
+
#
|
188
|
+
#
|
189
|
+
# Lazily enumerates over only the unique words in the wordlist, filtering
|
190
|
+
# out duplicates.
|
191
|
+
#
|
192
|
+
# @return [Operators::Unique]
|
193
|
+
# The lazy uniqueness of the wordlist.
|
194
|
+
#
|
195
|
+
# @example
|
196
|
+
# wordlist= Wordlist::List["foo", "bar", "baz", "qux"]
|
197
|
+
# (wordlist + wordlist).uniq.each do |word|
|
198
|
+
# puts word
|
199
|
+
# end
|
200
|
+
# # foo
|
201
|
+
# # bar
|
202
|
+
# # baz
|
203
|
+
# # qux
|
204
|
+
#
|
205
|
+
# @api public
|
206
|
+
#
|
207
|
+
def uniq
|
208
|
+
Operators::Unique.new(self)
|
209
|
+
end
|
210
|
+
|
211
|
+
#
|
212
|
+
# @group Modifiers
|
213
|
+
#
|
214
|
+
|
215
|
+
#
|
216
|
+
# Lazily calls `String#tr` on each word in the wordlist.
|
217
|
+
#
|
218
|
+
# @param [String] chars
|
219
|
+
# The characters or character range to replace.
|
220
|
+
#
|
221
|
+
# @param [String] replace
|
222
|
+
# The characters or character range to use as the replacement.
|
223
|
+
#
|
224
|
+
# @return [Tr]
|
225
|
+
# The lazy `String#tr` modification of the wordlist.
|
226
|
+
#
|
227
|
+
# @example
|
228
|
+
# wordlist = Wordlist::List["foo", "bar", "baz"]
|
229
|
+
# wordlist.capitalize.each do |word|
|
230
|
+
# puts word
|
231
|
+
# end
|
232
|
+
# # Foo
|
233
|
+
# # Bar
|
234
|
+
# # Baz
|
235
|
+
#
|
236
|
+
# @api public
|
237
|
+
#
|
238
|
+
def tr(chars,replace)
|
239
|
+
Modifiers::Tr.new(self,chars,replace)
|
240
|
+
end
|
241
|
+
|
242
|
+
#
|
243
|
+
# Lazily calls `String#sub` on each word in the wordlist.
|
244
|
+
#
|
245
|
+
# @param [Regexp, String] pattern
|
246
|
+
# The pattern to replace.
|
247
|
+
#
|
248
|
+
# @param [String, Hash, nil] replace
|
249
|
+
# The characters or character range to use as the replacement.
|
250
|
+
#
|
251
|
+
# @yield [match]
|
252
|
+
# The given block will be call to replace the matched substring,
|
253
|
+
# if `replace` is nil.
|
254
|
+
#
|
255
|
+
# @yieldparam [String] match
|
256
|
+
# A matched substring.
|
257
|
+
#
|
258
|
+
# @return [Sub]
|
259
|
+
# The lazy `String#sub` modification of the wordlist.
|
260
|
+
#
|
261
|
+
# @example
|
262
|
+
# wordlist = Wordlist::List["foo", "bar", "baz"]
|
263
|
+
# wordlist.sub(/o/, '0').each do |word|
|
264
|
+
# puts word
|
265
|
+
# end
|
266
|
+
# # f0o
|
267
|
+
# # bar
|
268
|
+
# # baz
|
269
|
+
#
|
270
|
+
# @api public
|
271
|
+
#
|
272
|
+
def sub(pattern,replace=nil,&block)
|
273
|
+
if replace
|
274
|
+
Modifiers::Sub.new(self,pattern,replace,&block)
|
275
|
+
else
|
276
|
+
Modifiers::Sub.new(self,pattern,&block)
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
#
|
281
|
+
# Lazily calls `String#gsub` on each word in the wordlist.
|
282
|
+
#
|
283
|
+
# @param [Regexp, String] pattern
|
284
|
+
# The pattern to replace.
|
285
|
+
#
|
286
|
+
# @param [String, Hash, nil] replace
|
287
|
+
# The characters or character range to use as the replacement.
|
288
|
+
#
|
289
|
+
# @yield [match]
|
290
|
+
# The given block will be call to replace the matched substring,
|
291
|
+
# if `replace` is nil.
|
292
|
+
#
|
293
|
+
# @yieldparam [String] match
|
294
|
+
# A matched substring.
|
295
|
+
#
|
296
|
+
# @return [Gsub]
|
297
|
+
# The lazy `String#gsub` modification of the wordlist.
|
298
|
+
#
|
299
|
+
# @example
|
300
|
+
# wordlist = Wordlist::List["Foo", "BAR", "bAz"]
|
301
|
+
# wordlist.gsub(/o/,'0').each do |word|
|
302
|
+
# puts word
|
303
|
+
# end
|
304
|
+
# # f00
|
305
|
+
# # bar
|
306
|
+
# # baz
|
307
|
+
#
|
308
|
+
# @api public
|
309
|
+
#
|
310
|
+
def gsub(pattern,replace=nil,&block)
|
311
|
+
if replace
|
312
|
+
Modifiers::Gsub.new(self,pattern,replace,&block)
|
313
|
+
else
|
314
|
+
Modifiers::Gsub.new(self,pattern,&block)
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
318
|
+
#
|
319
|
+
# Lazily calls `String#capitalize` on each word in the wordlist.
|
320
|
+
#
|
321
|
+
# @return [Capitalize]
|
322
|
+
# The lazy `String#gsub` modification of the wordlist.
|
323
|
+
#
|
324
|
+
# @example
|
325
|
+
# wordlist = Wordlist::List["foo", "bar", "baz"]
|
326
|
+
# wordlist.capitalize.each do |word|
|
327
|
+
# puts word
|
328
|
+
# end
|
329
|
+
# # Foo
|
330
|
+
# # Bar
|
331
|
+
# # Baz
|
332
|
+
#
|
333
|
+
# @api public
|
334
|
+
#
|
335
|
+
def capitalize
|
336
|
+
Modifiers::Capitalize.new(self)
|
337
|
+
end
|
338
|
+
|
339
|
+
#
|
340
|
+
# Lazily calls `String#upcase` on each word in the wordlist.
|
341
|
+
#
|
342
|
+
# @return [Upcase]
|
343
|
+
# The lazy `String#gsub` modification of the wordlist.
|
344
|
+
#
|
345
|
+
# @example
|
346
|
+
# wordlist = Wordlist::List["foo", "bar", "baz"]
|
347
|
+
# wordlist.upcase.each do |word|
|
348
|
+
# puts word
|
349
|
+
# end
|
350
|
+
# # FOO
|
351
|
+
# # BAR
|
352
|
+
# # BAZ
|
353
|
+
#
|
354
|
+
# @api public
|
355
|
+
#
|
356
|
+
def upcase
|
357
|
+
Modifiers::Upcase.new(self)
|
358
|
+
end
|
359
|
+
|
360
|
+
#
|
361
|
+
# Lazily calls `String#downcase` on each word in the wordlist.
|
362
|
+
#
|
363
|
+
# @return [Downcase]
|
364
|
+
# The lazy `String#gsub` modification of the wordlist.
|
365
|
+
#
|
366
|
+
# @example
|
367
|
+
# wordlist = Wordlist::List["Foo", "BAR", "bAz"]
|
368
|
+
# wordlist.downcase.each do |word|
|
369
|
+
# puts word
|
370
|
+
# end
|
371
|
+
# # foo
|
372
|
+
# # bar
|
373
|
+
# # baz
|
374
|
+
#
|
375
|
+
# @api public
|
376
|
+
#
|
377
|
+
def downcase
|
378
|
+
Modifiers::Downcase.new(self)
|
379
|
+
end
|
380
|
+
|
381
|
+
#
|
382
|
+
# Lazily performs every combination of a string substitution on every word
|
383
|
+
# in the wordlist.
|
384
|
+
#
|
385
|
+
# @param [Regexp, String] pattern
|
386
|
+
# The pattern to replace.
|
387
|
+
#
|
388
|
+
# @param [String, Hash, nil] replace
|
389
|
+
# The characters or character range to use as the replacement.
|
390
|
+
#
|
391
|
+
# @yield [match]
|
392
|
+
# The given block will be call to replace the matched substring,
|
393
|
+
# if `replace` is nil.
|
394
|
+
#
|
395
|
+
# @yieldparam [String] match
|
396
|
+
# A matched substring.
|
397
|
+
#
|
398
|
+
# @return [Mutate]
|
399
|
+
# The lazy `String#gsub` modification of the wordlist.
|
400
|
+
#
|
401
|
+
# @example
|
402
|
+
# wordlist = Wordlist::List["foo", "bar", "baz"]
|
403
|
+
# wordlist.mutate(/[oa]/, {'o' => '0', 'a' => '@'}).each do |word|
|
404
|
+
# puts word
|
405
|
+
# end
|
406
|
+
# # foo
|
407
|
+
# # f0o
|
408
|
+
# # fo0
|
409
|
+
# # f00
|
410
|
+
# # bar
|
411
|
+
# # b@r
|
412
|
+
# # baz
|
413
|
+
# # b@z
|
414
|
+
#
|
415
|
+
# @api public
|
416
|
+
#
|
417
|
+
def mutate(pattern,replace=nil,&block)
|
418
|
+
if replace
|
419
|
+
Modifiers::Mutate.new(self,pattern,replace,&block)
|
420
|
+
else
|
421
|
+
Modifiers::Mutate.new(self,pattern,&block)
|
422
|
+
end
|
423
|
+
end
|
424
|
+
|
425
|
+
#
|
426
|
+
# Lazily enumerates over every uppercase/lowercase variation of the word.
|
427
|
+
#
|
428
|
+
# @return [EachCase]
|
429
|
+
# The lazy `String#gsub` modification of the wordlist.
|
430
|
+
#
|
431
|
+
# @example
|
432
|
+
# wordlist = Wordlist::List["foo", "bar"]
|
433
|
+
# wordlist.mutate_case.each do |word|
|
434
|
+
# puts word
|
435
|
+
# end
|
436
|
+
# # foo
|
437
|
+
# # Foo
|
438
|
+
# # fOo
|
439
|
+
# # foO
|
440
|
+
# # FOo
|
441
|
+
# # FoO
|
442
|
+
# # fOO
|
443
|
+
# # FOO
|
444
|
+
# # bar
|
445
|
+
# # Bar
|
446
|
+
# # bAr
|
447
|
+
# # baR
|
448
|
+
# # BAr
|
449
|
+
# # BaR
|
450
|
+
# # bAR
|
451
|
+
# # BAR
|
452
|
+
#
|
453
|
+
# @api public
|
454
|
+
#
|
455
|
+
def mutate_case
|
456
|
+
Modifiers::MutateCase.new(self)
|
457
|
+
end
|
458
|
+
end
|
459
|
+
|
460
|
+
Operators::Operator.send :include, ListMethods
|
461
|
+
Modifiers::Modifier.send :include, ListMethods
|
462
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'wordlist/modifiers/modifier'
|
2
|
+
|
3
|
+
module Wordlist
|
4
|
+
module Modifiers
|
5
|
+
#
|
6
|
+
# Lazily calls `String#capitalize` on every word in the wordlist.
|
7
|
+
#
|
8
|
+
# @since 1.0.0
|
9
|
+
#
|
10
|
+
class Capitalize < Modifier
|
11
|
+
|
12
|
+
#
|
13
|
+
# Enumerates over every capitalized word in the wordlist.
|
14
|
+
#
|
15
|
+
# @yield [word]
|
16
|
+
# The given block will be passed each capitalized word.
|
17
|
+
#
|
18
|
+
# @yieldparam [String] word
|
19
|
+
# A capitalized word from the wordlist.
|
20
|
+
#
|
21
|
+
# @return [Enumerator]
|
22
|
+
# If no block is given, an Enumerator object will be returned.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
# wordlist = Wordlist::List["foo", "bar", "baz"]
|
26
|
+
# wordlist.capitalize.each do |word|
|
27
|
+
# puts word
|
28
|
+
# end
|
29
|
+
# # Foo
|
30
|
+
# # Bar
|
31
|
+
# # Baz
|
32
|
+
#
|
33
|
+
# @api public
|
34
|
+
#
|
35
|
+
def each
|
36
|
+
return enum_for(__method__) unless block_given?
|
37
|
+
|
38
|
+
@wordlist.each do |word|
|
39
|
+
yield word.capitalize
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'wordlist/modifiers/modifier'
|
2
|
+
|
3
|
+
module Wordlist
|
4
|
+
module Modifiers
|
5
|
+
#
|
6
|
+
# Lazily calls `String#downcase` on every word in the wordlist.
|
7
|
+
#
|
8
|
+
# @since 1.0.0
|
9
|
+
#
|
10
|
+
class Downcase < Modifier
|
11
|
+
|
12
|
+
#
|
13
|
+
# Enumerates over every `downcase`d word in the wordlist.
|
14
|
+
#
|
15
|
+
# @yield [word]
|
16
|
+
# The given block will be passed each `downcase`d word.
|
17
|
+
#
|
18
|
+
# @yieldparam [String] word
|
19
|
+
# A `downcase`d word.
|
20
|
+
#
|
21
|
+
# @return [Enumerator]
|
22
|
+
# If no block is given, an Enumerator object will be returned.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
# wordlist = Wordlist::List["Foo", "BAR", "bAz"]
|
26
|
+
# wordlist.downcase.each do |word|
|
27
|
+
# puts word
|
28
|
+
# end
|
29
|
+
# # foo
|
30
|
+
# # bar
|
31
|
+
# # baz
|
32
|
+
#
|
33
|
+
# @api public
|
34
|
+
#
|
35
|
+
def each
|
36
|
+
return enum_for(__method__) unless block_given?
|
37
|
+
|
38
|
+
@wordlist.each do |word|
|
39
|
+
yield word.downcase
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'wordlist/modifiers/sub'
|
2
|
+
|
3
|
+
module Wordlist
|
4
|
+
module Modifiers
|
5
|
+
#
|
6
|
+
# Lazily calls `String#gsub` on every word in the wordlist.
|
7
|
+
#
|
8
|
+
# @since 1.0.0
|
9
|
+
#
|
10
|
+
class Gsub < Sub
|
11
|
+
|
12
|
+
#
|
13
|
+
# Enumerates over every `gsub`ed word in the wordlist.
|
14
|
+
#
|
15
|
+
# @yield [word]
|
16
|
+
# The given block will be passed each `gsub`ed word.
|
17
|
+
#
|
18
|
+
# @yieldparam [String] word
|
19
|
+
# A `gsub`ed word from the wordlist.
|
20
|
+
#
|
21
|
+
# @return [Enumerator]
|
22
|
+
# If no block is given, an Enumerator object will be returned.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
# wordlist = Wordlist::List["Foo", "BAR", "bAz"]
|
26
|
+
# wordlist.gsub(/o/,'0').each do |word|
|
27
|
+
# puts word
|
28
|
+
# end
|
29
|
+
# # f00
|
30
|
+
# # bar
|
31
|
+
# # baz
|
32
|
+
#
|
33
|
+
# @api public
|
34
|
+
#
|
35
|
+
def each
|
36
|
+
return enum_for(__method__) unless block_given?
|
37
|
+
|
38
|
+
if @replace
|
39
|
+
@wordlist.each do |word|
|
40
|
+
yield word.gsub(@pattern,@replace)
|
41
|
+
end
|
42
|
+
else
|
43
|
+
@wordlist.each do |word|
|
44
|
+
yield word.gsub(@pattern,&block)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Wordlist
|
2
|
+
module Modifiers
|
3
|
+
#
|
4
|
+
# Modifier base class.
|
5
|
+
#
|
6
|
+
# @since 1.0.0
|
7
|
+
#
|
8
|
+
class Modifier
|
9
|
+
|
10
|
+
include Enumerable
|
11
|
+
|
12
|
+
# The wordlist to modify.
|
13
|
+
#
|
14
|
+
# @return [Enumerable]
|
15
|
+
attr_reader :wordlist
|
16
|
+
|
17
|
+
#
|
18
|
+
# Initializes the modifier.
|
19
|
+
#
|
20
|
+
# @param [Enumerable] wordlist
|
21
|
+
# The wordlist to modify.
|
22
|
+
#
|
23
|
+
def initialize(wordlist)
|
24
|
+
@wordlist = wordlist
|
25
|
+
end
|
26
|
+
|
27
|
+
#
|
28
|
+
# Enumerates over every modification of every word in the wordlist.
|
29
|
+
#
|
30
|
+
# @yield [word]
|
31
|
+
#
|
32
|
+
# @yieldparam [String] word
|
33
|
+
#
|
34
|
+
# @return [Enumerator]
|
35
|
+
#
|
36
|
+
# @abstract
|
37
|
+
#
|
38
|
+
def each(&block)
|
39
|
+
raise(NotImplementedError,"#{self.class}##{__method__} was not implemented")
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|