Created
May 26, 2015 18:08
-
-
Save manewitz/df1f8081edea346bc472 to your computer and use it in GitHub Desktop.
Ruby String Token Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Extracted library from a deprecated app | |
class Token | |
PREFIXES = ['ab', 'ac', 'acr', 'acl', 'ad', 'adr', 'ah', 'ar', 'aw', 'ay', 'br', 'bl', 'cl', 'cr', 'ch', 'dr', 'dw', 'en', 'ey', 'in', 'im', 'iy', 'oy', 'och', 'on', 'qu', 'sl', 'sh', 'sw', 'tr', 'th', 'thr', 'un', 'st', 'str', 'kn'] | |
DIPTHONGS = ['ae', 'au', 'ea','ou','ei','ie','ia','ee','oo','eo','io'] | |
CONSONANT_PAIRS = ['bb', 'bl', 'br', 'ck', 'cr', 'ch', 'dd', 'dr', 'gh', 'gr', 'gn', 'gg', 'lb', 'ld', 'lk', 'lp', 'mb', 'mm', 'nc', 'nch', 'nd', 'ng', 'nn', 'nt', 'pp', 'pl', 'pr', 'rr', 'rch', 'rs', 'rsh', 'rt', 'sh', 'th', 'tt', 'st', 'str'] | |
POSTFIXES = ['able', 'act', 'am', 'ams', 'ect', 'ed', 'edge', 'en', 'er', 'ful', 'ia', 'ier', 'ies', 'illy', 'im', 'ing', 'ium', 'is', 'less', 'or', 'up', 'ups', 'y', 'igle', 'ogle', 'agle', 'ist', 'est'] | |
VOWELS = ['a', 'e', 'i', 'o', 'u'] | |
CONSONANTS = ('a'..'z').to_a - VOWELS | |
class << self | |
def word | |
word = '' | |
until word.size > 5 do | |
word = prefix + vowel + consonant + POSTFIXES.sample | |
end | |
word | |
end | |
private | |
def hi_rand_val? | |
rand(10) > 8 | |
end | |
def prefix | |
if hi_rand_val? | |
PREFIXES.sample.capitalize | |
else | |
consonant.capitalize | |
end | |
end | |
def vowel | |
if hi_rand_val? | |
DIPTHONGS.sample | |
else | |
VOWELS.sample | |
end | |
end | |
def consonant | |
if hi_rand_val? | |
CONSONANT_PAIRS.sample | |
else | |
CONSONANTS.sample.capitalize | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment