Skip to content

Instantly share code, notes, and snippets.

@manewitz manewitz/token.rb
Created May 26, 2015

Embed
What would you like to do?
Ruby String Token Generator
# 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
You can’t perform that action at this time.