wordlist 0.1.1 → 1.0.1
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 +28 -0
- data/.gitignore +6 -3
- data/ChangeLog.md +55 -1
- data/Gemfile +15 -0
- data/LICENSE.txt +1 -3
- data/README.md +301 -60
- 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 +13 -12
- data/lib/wordlist/abstract_wordlist.rb +25 -0
- data/lib/wordlist/builder.rb +172 -138
- data/lib/wordlist/cli.rb +459 -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 +177 -0
- data/lib/wordlist/format.rb +39 -0
- data/lib/wordlist/lexer/lang.rb +34 -0
- data/lib/wordlist/lexer/stop_words.rb +69 -0
- data/lib/wordlist/lexer.rb +221 -0
- data/lib/wordlist/list_methods.rb +462 -0
- data/lib/wordlist/modifiers/capitalize.rb +46 -0
- data/lib/wordlist/modifiers/downcase.rb +46 -0
- data/lib/wordlist/modifiers/gsub.rb +52 -0
- data/lib/wordlist/modifiers/modifier.rb +44 -0
- data/lib/wordlist/modifiers/mutate.rb +134 -0
- data/lib/wordlist/modifiers/mutate_case.rb +26 -0
- data/lib/wordlist/modifiers/sub.rb +98 -0
- data/lib/wordlist/modifiers/tr.rb +72 -0
- data/lib/wordlist/modifiers/upcase.rb +46 -0
- data/lib/wordlist/modifiers.rb +9 -0
- data/lib/wordlist/operators/binary_operator.rb +39 -0
- data/lib/wordlist/operators/concat.rb +48 -0
- data/lib/wordlist/operators/intersect.rb +56 -0
- data/lib/wordlist/operators/operator.rb +29 -0
- data/lib/wordlist/operators/power.rb +73 -0
- data/lib/wordlist/operators/product.rb +51 -0
- data/lib/wordlist/operators/subtract.rb +55 -0
- data/lib/wordlist/operators/unary_operator.rb +30 -0
- data/lib/wordlist/operators/union.rb +62 -0
- data/lib/wordlist/operators/unique.rb +53 -0
- data/lib/wordlist/operators.rb +8 -0
- data/lib/wordlist/unique_filter.rb +41 -61
- data/lib/wordlist/version.rb +4 -2
- data/lib/wordlist/words.rb +72 -0
- data/lib/wordlist.rb +104 -2
- data/spec/abstract_list_spec.rb +18 -0
- data/spec/builder_spec.rb +220 -76
- data/spec/cli_spec.rb +802 -0
- data/spec/compression/reader_spec.rb +137 -0
- data/spec/compression/writer_spec.rb +194 -0
- data/spec/file_spec.rb +269 -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 +718 -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/unary_operator_spec.rb +14 -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
- data/wordlist.gemspec +1 -0
- metadata +164 -126
- 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/classes/parser_class.rb +0 -7
- data/spec/classes/test_list.rb +0 -9
- 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
|
+
# frozen_string_literal: true
|
2
|
+
require 'wordlist/operators'
|
3
|
+
require 'wordlist/modifiers'
|
4
|
+
|
5
|
+
module Wordlist
|
6
|
+
#
|
7
|
+
# List operator and modifier methods.
|
8
|
+
#
|
9
|
+
# @since 1.0.0
|
10
|
+
#
|
11
|
+
module ListMethods
|
12
|
+
#
|
13
|
+
# @group Operators
|
14
|
+
#
|
15
|
+
|
16
|
+
#
|
17
|
+
# Lazily enumerates over the first wordlist, then the second.
|
18
|
+
#
|
19
|
+
# @param [Enumerable] other
|
20
|
+
# The other wordlist to concat.
|
21
|
+
#
|
22
|
+
# @return [Operators::Concat]
|
23
|
+
# The lazily concatenated wordlists.
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
# wordlist1 = Wordlist::Words["foo", "bar", "baz"]
|
27
|
+
# wordlist2 = Wordlist::Words["abc", "xyz"]
|
28
|
+
# (wordlist1 + wordlist2).each do |word|
|
29
|
+
# puts word
|
30
|
+
# end
|
31
|
+
# # foo
|
32
|
+
# # bar
|
33
|
+
# # baz
|
34
|
+
# # abc
|
35
|
+
# # xyz
|
36
|
+
#
|
37
|
+
# @api public
|
38
|
+
#
|
39
|
+
def concat(other)
|
40
|
+
Operators::Concat.new(self,other)
|
41
|
+
end
|
42
|
+
|
43
|
+
alias + concat
|
44
|
+
|
45
|
+
#
|
46
|
+
# Lazily enumerates over every word in the first wordlist, that is not in
|
47
|
+
# the second wordlist.
|
48
|
+
#
|
49
|
+
# @param [Enumerable] other
|
50
|
+
# The other wordlist to subtract.
|
51
|
+
#
|
52
|
+
# @return [Operators::Subtract]
|
53
|
+
# The lazy subtraction of the two wordlists.
|
54
|
+
#
|
55
|
+
# @example
|
56
|
+
# wordlist1 = Wordlist::Words["foo", "bar", baz", "qux"]
|
57
|
+
# wordlist2 = Wordlist::Words["bar", "qux"]
|
58
|
+
# (wordlist1 - wordlist2).each do |word|
|
59
|
+
# puts word
|
60
|
+
# end
|
61
|
+
# # foo
|
62
|
+
# # baz
|
63
|
+
#
|
64
|
+
# @api public
|
65
|
+
#
|
66
|
+
def subtract(other)
|
67
|
+
Operators::Subtract.new(self,other)
|
68
|
+
end
|
69
|
+
|
70
|
+
alias - subtract
|
71
|
+
|
72
|
+
#
|
73
|
+
# Lazily enumerates over the combination of the words from two wordlists.
|
74
|
+
#
|
75
|
+
# @param [Enumerable] other
|
76
|
+
# The other wordlist to combine with.
|
77
|
+
#
|
78
|
+
# @return [Operators::Product]
|
79
|
+
# The lazy product of the two wordlists.
|
80
|
+
#
|
81
|
+
# @example
|
82
|
+
# wordlist1 = Wordlist::Words["foo", "bar"]
|
83
|
+
# wordlist2 = Wordlist::Words["ABC", "XYZ"]
|
84
|
+
# (wordlist1 * wordlist2).each do |word|
|
85
|
+
# puts word
|
86
|
+
# end
|
87
|
+
# # fooABC
|
88
|
+
# # fooXYZ
|
89
|
+
# # barABC
|
90
|
+
# # barXYZ
|
91
|
+
#
|
92
|
+
# @api public
|
93
|
+
#
|
94
|
+
def product(other)
|
95
|
+
Operators::Product.new(self,other)
|
96
|
+
end
|
97
|
+
|
98
|
+
alias * product
|
99
|
+
|
100
|
+
#
|
101
|
+
# Lazily enumerates over every combination of words in the wordlist.
|
102
|
+
#
|
103
|
+
# @param [Integer] exponent
|
104
|
+
# The number of times the wordlist will be combined with itself.
|
105
|
+
#
|
106
|
+
# @return [Operators::Power]
|
107
|
+
# The lazy combination of the wordlist.
|
108
|
+
#
|
109
|
+
# @example
|
110
|
+
# wordlist = Wordlist::Words["foo", "bar"]
|
111
|
+
# (wordlist ** 3).each do |word|
|
112
|
+
# puts word
|
113
|
+
# end
|
114
|
+
# # foofoofoo
|
115
|
+
# # foofoobar
|
116
|
+
# # foobarfoo
|
117
|
+
# # foobarbar
|
118
|
+
# # barfoofoo
|
119
|
+
# # barfoobar
|
120
|
+
# # barbarfoo
|
121
|
+
# # barbarbar
|
122
|
+
#
|
123
|
+
# @api public
|
124
|
+
#
|
125
|
+
def power(exponent)
|
126
|
+
Operators::Power.new(self,exponent)
|
127
|
+
end
|
128
|
+
|
129
|
+
alias ** power
|
130
|
+
|
131
|
+
#
|
132
|
+
# Lazily enumerates over every word that belongs to both wordlists.
|
133
|
+
#
|
134
|
+
# @param [Enumerable] other
|
135
|
+
# The other wordlist to intersect with.
|
136
|
+
#
|
137
|
+
# @return [Operators::Intersect]
|
138
|
+
# The lazy intersection of the two wordlists.
|
139
|
+
#
|
140
|
+
# @example
|
141
|
+
# wordlist1 = Wordlist::Words["foo", "bar", "baz", "qux"]
|
142
|
+
# wordlist2 = Wordlist::Words["xyz", "bar", "abc", "qux"]
|
143
|
+
# (wordlist1 & wordlist2).each do |word|
|
144
|
+
# puts word
|
145
|
+
# end
|
146
|
+
# # bar
|
147
|
+
# # qux
|
148
|
+
#
|
149
|
+
# @api public
|
150
|
+
#
|
151
|
+
def intersect(other)
|
152
|
+
Operators::Intersect.new(self,other)
|
153
|
+
end
|
154
|
+
|
155
|
+
alias & intersect
|
156
|
+
|
157
|
+
#
|
158
|
+
# Lazily enumerates over words from both wordlists, filtering out any
|
159
|
+
# duplicates.
|
160
|
+
#
|
161
|
+
# @param [Enumerable] other
|
162
|
+
# The other wordlist to union with.
|
163
|
+
#
|
164
|
+
# @return [Operators::Union]
|
165
|
+
# The lazy union of the two wordlists.
|
166
|
+
#
|
167
|
+
# @example
|
168
|
+
# wordlist1 = Wordlist::Words["foo", "bar", "baz", "qux"]
|
169
|
+
# wordlist2 = Wordlist::Words["xyz", "bar", "abc", "qux"]
|
170
|
+
# (wordlist1 | wordlist2).each do |word|
|
171
|
+
# puts word
|
172
|
+
# end
|
173
|
+
# # foo
|
174
|
+
# # bar
|
175
|
+
# # baz
|
176
|
+
# # qux
|
177
|
+
# # xyz
|
178
|
+
# # abc
|
179
|
+
#
|
180
|
+
# @api public
|
181
|
+
#
|
182
|
+
def union(other)
|
183
|
+
Operators::Union.new(self,other)
|
184
|
+
end
|
185
|
+
|
186
|
+
alias | union
|
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::Words["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::Words["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::Words["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::Words["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::Words["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::Words["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::Words["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::Words["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::Words["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,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'wordlist/modifiers/modifier'
|
3
|
+
|
4
|
+
module Wordlist
|
5
|
+
module Modifiers
|
6
|
+
#
|
7
|
+
# Lazily calls `String#capitalize` on every word in the wordlist.
|
8
|
+
#
|
9
|
+
# @since 1.0.0
|
10
|
+
#
|
11
|
+
class Capitalize < Modifier
|
12
|
+
|
13
|
+
#
|
14
|
+
# Enumerates over every capitalized word in the wordlist.
|
15
|
+
#
|
16
|
+
# @yield [word]
|
17
|
+
# The given block will be passed each capitalized word.
|
18
|
+
#
|
19
|
+
# @yieldparam [String] word
|
20
|
+
# A capitalized word from the wordlist.
|
21
|
+
#
|
22
|
+
# @return [Enumerator]
|
23
|
+
# If no block is given, an Enumerator object will be returned.
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
# wordlist = Wordlist::Words["foo", "bar", "baz"]
|
27
|
+
# wordlist.capitalize.each do |word|
|
28
|
+
# puts word
|
29
|
+
# end
|
30
|
+
# # Foo
|
31
|
+
# # Bar
|
32
|
+
# # Baz
|
33
|
+
#
|
34
|
+
# @api public
|
35
|
+
#
|
36
|
+
def each
|
37
|
+
return enum_for(__method__) unless block_given?
|
38
|
+
|
39
|
+
@wordlist.each do |word|
|
40
|
+
yield word.capitalize
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'wordlist/modifiers/modifier'
|
3
|
+
|
4
|
+
module Wordlist
|
5
|
+
module Modifiers
|
6
|
+
#
|
7
|
+
# Lazily calls `String#downcase` on every word in the wordlist.
|
8
|
+
#
|
9
|
+
# @since 1.0.0
|
10
|
+
#
|
11
|
+
class Downcase < Modifier
|
12
|
+
|
13
|
+
#
|
14
|
+
# Enumerates over every `downcase`d word in the wordlist.
|
15
|
+
#
|
16
|
+
# @yield [word]
|
17
|
+
# The given block will be passed each `downcase`d word.
|
18
|
+
#
|
19
|
+
# @yieldparam [String] word
|
20
|
+
# A `downcase`d word.
|
21
|
+
#
|
22
|
+
# @return [Enumerator]
|
23
|
+
# If no block is given, an Enumerator object will be returned.
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
# wordlist = Wordlist::Words["Foo", "BAR", "bAz"]
|
27
|
+
# wordlist.downcase.each do |word|
|
28
|
+
# puts word
|
29
|
+
# end
|
30
|
+
# # foo
|
31
|
+
# # bar
|
32
|
+
# # baz
|
33
|
+
#
|
34
|
+
# @api public
|
35
|
+
#
|
36
|
+
def each
|
37
|
+
return enum_for(__method__) unless block_given?
|
38
|
+
|
39
|
+
@wordlist.each do |word|
|
40
|
+
yield word.downcase
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'wordlist/modifiers/sub'
|
3
|
+
|
4
|
+
module Wordlist
|
5
|
+
module Modifiers
|
6
|
+
#
|
7
|
+
# Lazily calls `String#gsub` on every word in the wordlist.
|
8
|
+
#
|
9
|
+
# @since 1.0.0
|
10
|
+
#
|
11
|
+
class Gsub < Sub
|
12
|
+
|
13
|
+
#
|
14
|
+
# Enumerates over every `gsub`ed word in the wordlist.
|
15
|
+
#
|
16
|
+
# @yield [word]
|
17
|
+
# The given block will be passed each `gsub`ed word.
|
18
|
+
#
|
19
|
+
# @yieldparam [String] word
|
20
|
+
# A `gsub`ed word from the wordlist.
|
21
|
+
#
|
22
|
+
# @return [Enumerator]
|
23
|
+
# If no block is given, an Enumerator object will be returned.
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
# wordlist = Wordlist::Words["Foo", "BAR", "bAz"]
|
27
|
+
# wordlist.gsub(/o/,'0').each do |word|
|
28
|
+
# puts word
|
29
|
+
# end
|
30
|
+
# # f00
|
31
|
+
# # bar
|
32
|
+
# # baz
|
33
|
+
#
|
34
|
+
# @api public
|
35
|
+
#
|
36
|
+
def each
|
37
|
+
return enum_for(__method__) unless block_given?
|
38
|
+
|
39
|
+
if @replace
|
40
|
+
@wordlist.each do |word|
|
41
|
+
yield word.gsub(@pattern,@replace)
|
42
|
+
end
|
43
|
+
else
|
44
|
+
@wordlist.each do |word|
|
45
|
+
yield word.gsub(@pattern,&block)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
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
|