Module: Wordlist::ListMethods

Included in:
AbstractWordlist
Defined in:
lib/wordlist/list_methods.rb

Overview

List operator and modifier methods.

Since:

  • 1.0.0

Operators collapse

Modifiers collapse

Instance Method Details

#capitalizeCapitalize

Lazily calls String#capitalize on each word in the wordlist.

Examples:

wordlist = Wordlist::Words["foo", "bar", "baz"]
wordlist.capitalize.each do |word|
  puts word
end
# Foo
# Bar
# Baz

Returns:

  • (Capitalize)

    The lazy String#gsub modification of the wordlist.

Since:

  • 1.0.0



335
336
337
# File 'lib/wordlist/list_methods.rb', line 335

def capitalize
  Modifiers::Capitalize.new(self)
end

#concat(other) ⇒ Operators::Concat Also known as: +

Lazily enumerates over the first wordlist, then the second.

Examples:

wordlist1 = Wordlist::Words["foo", "bar", "baz"]
wordlist2 = Wordlist::Words["abc", "xyz"]
(wordlist1 + wordlist2).each do |word|
  puts word
end
# foo
# bar
# baz
# abc
# xyz

Parameters:

  • other (Enumerable)

    The other wordlist to concat.

Returns:

Since:

  • 1.0.0



39
40
41
# File 'lib/wordlist/list_methods.rb', line 39

def concat(other)
  Operators::Concat.new(self,other)
end

#downcaseDowncase

Lazily calls String#downcase on each word in the wordlist.

Examples:

wordlist = Wordlist::Words["Foo", "BAR", "bAz"]
wordlist.downcase.each do |word|
  puts word
end
# foo
# bar
# baz

Returns:

  • (Downcase)

    The lazy String#gsub modification of the wordlist.

Since:

  • 1.0.0



377
378
379
# File 'lib/wordlist/list_methods.rb', line 377

def downcase
  Modifiers::Downcase.new(self)
end

#gsub(pattern, replace = nil) {|match| ... } ⇒ Gsub

Lazily calls String#gsub on each word in the wordlist.

Examples:

wordlist = Wordlist::Words["Foo", "BAR", "bAz"]
wordlist.gsub(/o/,'0').each do |word|
  puts word
end
# f00
# bar
# baz

Parameters:

  • pattern (Regexp, String)

    The pattern to replace.

  • replace (String, Hash, nil) (defaults to: nil)

    The characters or character range to use as the replacement.

Yields:

  • (match)

    The given block will be call to replace the matched substring, if replace is nil.

Yield Parameters:

  • match (String)

    A matched substring.

Returns:

  • (Gsub)

    The lazy String#gsub modification of the wordlist.

Since:

  • 1.0.0



310
311
312
313
314
315
316
# File 'lib/wordlist/list_methods.rb', line 310

def gsub(pattern,replace=nil,&block)
  if replace
    Modifiers::Gsub.new(self,pattern,replace,&block)
  else
    Modifiers::Gsub.new(self,pattern,&block)
  end
end

#intersect(other) ⇒ Operators::Intersect Also known as: &

Lazily enumerates over every word that belongs to both wordlists.

Examples:

wordlist1 = Wordlist::Words["foo", "bar", "baz", "qux"]
wordlist2 = Wordlist::Words["xyz", "bar", "abc", "qux"]
(wordlist1 & wordlist2).each do |word|
  puts word
end
# bar
# qux

Parameters:

  • other (Enumerable)

    The other wordlist to intersect with.

Returns:

Since:

  • 1.0.0



151
152
153
# File 'lib/wordlist/list_methods.rb', line 151

def intersect(other)
  Operators::Intersect.new(self,other)
end

#mutate(pattern, replace = nil) {|match| ... } ⇒ Mutate

Lazily performs every combination of a string substitution on every word in the wordlist.

Examples:

wordlist = Wordlist::Words["foo", "bar", "baz"]
wordlist.mutate(/[oa]/, {'o' => '0', 'a' => '@'}).each do |word|
  puts word
end
# foo
# f0o
# fo0
# f00
# bar
# b@r
# baz
# b@z

Parameters:

  • pattern (Regexp, String)

    The pattern to replace.

  • replace (String, Hash, nil) (defaults to: nil)

    The characters or character range to use as the replacement.

Yields:

  • (match)

    The given block will be call to replace the matched substring, if replace is nil.

Yield Parameters:

  • match (String)

    A matched substring.

Returns:

  • (Mutate)

    The lazy String#gsub modification of the wordlist.

Since:

  • 1.0.0



417
418
419
420
421
422
423
# File 'lib/wordlist/list_methods.rb', line 417

def mutate(pattern,replace=nil,&block)
  if replace
    Modifiers::Mutate.new(self,pattern,replace,&block)
  else
    Modifiers::Mutate.new(self,pattern,&block)
  end
end

#mutate_caseEachCase

Lazily enumerates over every uppercase/lowercase variation of the word.

# foo # Foo # fOo # foO # FOo # FoO # fOO # FOO # bar # Bar # bAr # baR # BAr # BaR # bAR # BAR

Examples:

wordlist = Wordlist::Words["foo", "bar"]
wordlist.mutate_case.each do |word|
  puts word
end

Returns:

  • (EachCase)

    The lazy String#gsub modification of the wordlist.

Since:

  • 1.0.0



455
456
457
# File 'lib/wordlist/list_methods.rb', line 455

def mutate_case
  Modifiers::MutateCase.new(self)
end

#power(exponent) ⇒ Operators::Power Also known as: **

Lazily enumerates over every combination of words in the wordlist.

Examples:

wordlist = Wordlist::Words["foo", "bar"]
(wordlist ** 3).each do |word|
  puts word
end
# foofoofoo
# foofoobar
# foobarfoo
# foobarbar
# barfoofoo
# barfoobar
# barbarfoo
# barbarbar

Parameters:

  • exponent (Integer)

    The number of times the wordlist will be combined with itself.

Returns:

Since:

  • 1.0.0



125
126
127
# File 'lib/wordlist/list_methods.rb', line 125

def power(exponent)
  Operators::Power.new(self,exponent)
end

#product(other) ⇒ Operators::Product Also known as: *

Lazily enumerates over the combination of the words from two wordlists.

Examples:

wordlist1 = Wordlist::Words["foo", "bar"]
wordlist2 = Wordlist::Words["ABC", "XYZ"]
(wordlist1 * wordlist2).each do |word|
  puts word
end
# fooABC
# fooXYZ
# barABC
# barXYZ

Parameters:

  • other (Enumerable)

    The other wordlist to combine with.

Returns:

Since:

  • 1.0.0



94
95
96
# File 'lib/wordlist/list_methods.rb', line 94

def product(other)
  Operators::Product.new(self,other)
end

#sub(pattern, replace = nil) {|match| ... } ⇒ Sub

Lazily calls String#sub on each word in the wordlist.

Examples:

wordlist = Wordlist::Words["foo", "bar", "baz"]
wordlist.sub(/o/, '0').each do |word|
  puts word
end
# f0o
# bar
# baz

Parameters:

  • pattern (Regexp, String)

    The pattern to replace.

  • replace (String, Hash, nil) (defaults to: nil)

    The characters or character range to use as the replacement.

Yields:

  • (match)

    The given block will be call to replace the matched substring, if replace is nil.

Yield Parameters:

  • match (String)

    A matched substring.

Returns:

  • (Sub)

    The lazy String#sub modification of the wordlist.

Since:

  • 1.0.0



272
273
274
275
276
277
278
# File 'lib/wordlist/list_methods.rb', line 272

def sub(pattern,replace=nil,&block)
  if replace
    Modifiers::Sub.new(self,pattern,replace,&block)
  else
    Modifiers::Sub.new(self,pattern,&block)
  end
end

#subtract(other) ⇒ Operators::Subtract Also known as: -

Lazily enumerates over every word in the first wordlist, that is not in the second wordlist.

Examples:

wordlist1 = Wordlist::Words["foo", "bar", baz", "qux"]
wordlist2 = Wordlist::Words["bar", "qux"]
(wordlist1 - wordlist2).each do |word|
  puts word
end
# foo
# baz

Parameters:

  • other (Enumerable)

    The other wordlist to subtract.

Returns:

Since:

  • 1.0.0



66
67
68
# File 'lib/wordlist/list_methods.rb', line 66

def subtract(other)
  Operators::Subtract.new(self,other)
end

#tr(chars, replace) ⇒ Tr

Lazily calls String#tr on each word in the wordlist.

Examples:

wordlist = Wordlist::Words["foo", "bar", "baz"]
wordlist.capitalize.each do |word|
  puts word
end
# Foo
# Bar
# Baz

Parameters:

  • chars (String)

    The characters or character range to replace.

  • replace (String)

    The characters or character range to use as the replacement.

Returns:

  • (Tr)

    The lazy String#tr modification of the wordlist.

Since:

  • 1.0.0



238
239
240
# File 'lib/wordlist/list_methods.rb', line 238

def tr(chars,replace)
  Modifiers::Tr.new(self,chars,replace)
end

#union(other) ⇒ Operators::Union Also known as: |

Lazily enumerates over words from both wordlists, filtering out any duplicates.

Examples:

wordlist1 = Wordlist::Words["foo", "bar", "baz", "qux"]
wordlist2 = Wordlist::Words["xyz", "bar", "abc", "qux"]
(wordlist1 | wordlist2).each do |word|
  puts word
end
# foo
# bar
# baz
# qux
# xyz
# abc

Parameters:

  • other (Enumerable)

    The other wordlist to union with.

Returns:

Since:

  • 1.0.0



182
183
184
# File 'lib/wordlist/list_methods.rb', line 182

def union(other)
  Operators::Union.new(self,other)
end

#uniqOperators::Unique

Lazily enumerates over only the unique words in the wordlist, filtering out duplicates.

Examples:

wordlist= Wordlist::Words["foo", "bar", "baz", "qux"]
(wordlist + wordlist).uniq.each do |word|
  puts word
end
# foo
# bar
# baz
# qux

Returns:

Since:

  • 1.0.0



207
208
209
# File 'lib/wordlist/list_methods.rb', line 207

def uniq
  Operators::Unique.new(self)
end

#upcaseUpcase

Lazily calls String#upcase on each word in the wordlist.

Examples:

wordlist = Wordlist::Words["foo", "bar", "baz"]
wordlist.upcase.each do |word|
  puts word
end
# FOO
# BAR
# BAZ

Returns:

  • (Upcase)

    The lazy String#gsub modification of the wordlist.

Since:

  • 1.0.0



356
357
358
# File 'lib/wordlist/list_methods.rb', line 356

def upcase
  Modifiers::Upcase.new(self)
end