module Ronin::Support::Text::Typo
Generates typos in words.
## Core-Ext Methods
-
{String#each_typo}
-
{String#typo}
-
{String#typos}
@api public
@since 1.0.0
Constants
- CHANGE_SUFFIX
Typo
generator that changes the suffix of words.- DEFAULT
Default typo generator.
@note Does not include the {SWAP_SYMBOLS} typo rules.
- OMIT_CHARS
Typo
generator that repeats characters.- REPEAT_CHARS
Typo
generator that repeats characters.- SWAP_CHARS
Typo
generator that swaps neighboring characters.- SWAP_SYMBOLS
Typo
generator that swaps different symbols.
Public Class Methods
Typo
generator that changes the suffix of words.
@return [Generator]
@see CHANGE_SUFFIX
# File lib/ronin/support/text/typo.rb, line 158 def self.change_suffix CHANGE_SUFFIX end
Enumerates over every typo mistake for the given word.
@param [String] word
The given String.
@param [Hash{Symbol => Boolean}] kwargs
Additional keyword arguments.
@option kwargs [Boolean] omit
Enables/disables omission of repeated characters.
@option kwargs [Boolean] repeat
Enables/disables repeatition of single characters.
@option kwargs [Boolean] swap
Enables/disables swapping of certain common character pairs.
@option kwargs [Boolean] suffix
Enables/disables changing the suffixes of words.
@yield [typoed]
If a block is given, it will be passed each possible typo of the original String.
@yieldparam [String]
A modified version of the original String.
@return [Enumerator]
If no block is given, an Enumerator will be returned.
@see String#each_typo
@see String#typos
# File lib/ronin/support/text/typo.rb, line 263 def self.each_substitution(word,**kwargs,&block) generator(**kwargs).each_substitution(word,&block) end
Builds a set of typo substitution rules.
@param [Hash{Symbol => Boolean}] kwargs
Additional typo options.
@option kwargs [Boolean] :omit_chars
Whether to enable/disable omission of repeated characters.
@option kwargs [Boolean] :repeat_chars
Whether to enable/disable repeatition of single characters.
@option kwargs [Boolean] :swap_chars
Whether to enable/disable swapping of certain common character pairs.
@option kwargs [Boolean] :change_suffix
Whether to enable/disable changing the suffixes of words.
@return [Generator]
The typo generator.
# File lib/ronin/support/text/typo.rb, line 184 def self.generator(**kwargs) if kwargs.empty? DEFAULT else rules = [] rules.concat(OMIT_CHARS.rules) if kwargs[:omit_chars] rules.concat(REPEAT_CHARS.rules) if kwargs[:repeat_chars] rules.concat(SWAP_CHARS.rules) if kwargs[:swap_chars] rules.concat(SWAP_SYMBOLS.rules) if kwargs[:swap_symbols] rules.concat(CHANGE_SUFFIX.rules) if kwargs[:change_suffix] Generator.new(rules) end end
Typo
generator that repeats characters.
@return [Generator]
@see OMIT_CHARS
# File lib/ronin/support/text/typo.rb, line 114 def self.omit_chars OMIT_CHARS end
Typo
generator that repeats characters.
@return [Generator]
@see REPEAT_CHARS
# File lib/ronin/support/text/typo.rb, line 125 def self.repeat_chars REPEAT_CHARS end
Returns a random typo substitution for the given word.
@param [String] word
The given String.
@param [Hash{Symbol => Boolean}] kwargs
Additional keyword arguments.
@option kwargs [Boolean] omit
Enables/disables omission of repeated characters.
@option kwargs [Boolean] repeat
Enables/disables repeatition of single characters.
@option kwargs [Boolean] swap
Enables/disables swapping of certain common character pairs.
@option kwargs [Boolean] suffix
Enables/disables changing the suffixes of words.
@return [String]
A random typo of the given word.
@see String#typo
# File lib/ronin/support/text/typo.rb, line 225 def self.substitute(word,**kwargs) generator(**kwargs).substitute(word) end
Typo
generator that swaps neighboring characters.
@return [Generator]
@see SWAP_CHARS
# File lib/ronin/support/text/typo.rb, line 136 def self.swap_chars SWAP_CHARS end
Typo
generator that swaps different symbols.
@return [Generator]
@see SWAP_SYMBOLS
# File lib/ronin/support/text/typo.rb, line 147 def self.swap_symbols SWAP_SYMBOLS end