Skip to content

Instantly share code, notes, and snippets.

@roktas
Created May 31, 2014 21:58
Show Gist options
  • Save roktas/f0701df5f4149ffa87d9 to your computer and use it in GitHub Desktop.
Save roktas/f0701df5f4149ffa87d9 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
# encoding: utf-8
# Shamelessly stolen and adapted from https://github.com/raycchan/bazaar
require 'erb'
# Generate random names
class Rasgele # rubocop:disable ClassLength
RANDOM_FORMAT = '<%= superadjective %>-<%= supername %>-<%= random %>'
ORDERED_FORMAT = '<%= yearmonthday %>-<%= superadjective %>-<%= supername %>'
DEFAULT_FORMAT = RANDOM_FORMAT
DICTIONARY = {
en: {
adjectives: %w(
attractive
average
beautiful
big
broad
broken
bumpy
chubby
clean
colorful
colossal
crooked
curved
cute
damaged
dark
deep
dirty
dry
dull
dusty
fancy
fat
filthy
flat
gigantic
gorgeous
graceful
great
grotesque
high
hollow
huge
large
little
long
mammoth
massive
miniature
misty
muddy
narrow
petite
plain
precious
prickly
puny
quaint
round
scrawny
shallow
shiny
short
skinny
slimy
slippery
small
smooth
soft
steep
sticky
straight
strange
tall
teeny
tiny
ugly
unusual
wide
),
superadjectives: %w(
affectionate
amiable
arrogant
balmy
barren
benevolent
billowing
blessed
breezy
calm
celestial
charming
combative
composed
condemned
divine
dry
energized
enigmatic
exuberant
flowing
fluffy
fluttering
frightened
fuscia
gentle
greasy
grieving
harmonious
hollow
homeless
icy
indigo
inquisitive
itchy
joyful
jubilant
juicy
khaki
limitless
lush
mellow
merciful
merry
mirthful
moonlit
mysterious
natural
outrageous
pacific
parched
placid
pleasant
poised
purring
radioactive
resilient
scenic
screeching
sensitive
serene
snowy
solitary
spacial
squealing
stark
stunning
sunset
talented
tasteless
teal
thoughtless
thriving
tranquil
tropical
undisturbed
unsightly
unwavering
uplifting
voiceless
wandering
warm
wealthy
whispering
withered
wooden
zealous
),
names: %w(
anvil
arrow
axe
balloon
baseball
bathtub
bible
bike
bikini
bleach
blouse
blowdryer
book
bookmark
boombox
bottle cap
button
candle
candy wrapper
canvas
card
CD
cha
chainmail
chalk
charger
checkbook
clarinet
clay pot
clock
coffee maker
comb
cookie jar
cork
crayons
credit card
cushion
deodorant
detergent
dice
dollar bill
drum
eraser
eye liner
facewash
flag
flowers
flute
fork
gel
glasses
glowstick
grid paper
hairtie
hanger
hat
helmet
icecube
javelin
keychain
kilt
kite
knife
lace
lamp shade
leg warmers
lip gloss
lotion
mallet
map
microphone
model car
mousepad
nail
needle
outlet
paint brush
passport
pencil
pepperspray
photo album
piano
picture frame
piggy bank
pillow
pool stick
puddle
quilt
radio
receipt
remote control
rock
rope
rubberband
rubber duck
rug
sandpaper
scissors
scotchtape
screw
seatbelt
sharpie
shield
shoelace
shovel
sketchpad
slipper
soap
speakers
spear
sponge
spoon
sticky note
stockings
stone
suitcase
sunglasses
thermometer
thread
tire
tissuebox
tobacco
toothpaste
toothpick
vase
wheelbarrow
whiteout
zipper
),
supernames: %w(
abyss
atoll
aurora
autumn
badlands
beach
briars
brook
canopy
canyon
cavern
chasm
cliff
cove
crater
creek
darkness
dawn
desert
dew
dove
drylands
dusk
farm
fern
firefly
flowers
fog
foliage
forest
galaxy
garden
geyser
grove
hurricane
iceberg
lagoon
lake
leaves
marsh
meadow
mist
moss
mountain
oasis
ocean
peak
pebble
pine
plateau
pond
reef
reserve
resonance
sanctuary
sands
shelter
silence
smokescreen
snowflake
spring
storm
stream
summer
summit
sunrise
sunset
sunshine
surf
swamp
temple
thorns
tsunami
tundra
valley
volcano
waterfall
willow
winds
winter
)
},
}
def initialize(language = :en)
@words = DICTIONARY[language]
end
def superadjective
@words[:superadjectives].sample
end
def adjective
@words[:adjectives].sample
end
def supername
@words[:supernames].sample
end
def name
@words[:names].sample
end
def random
rand(0 - 9999).to_s
end
def daymonthyear(format = '%d%m%y')
Time.now.strftime(format)
end
alias_method :dmy, :daymonthyear
def yearmonthday(format = '%y%m%d')
Time.now.strftime(format)
end
alias_method :ymd, :yearmonthday
def rasgele(format = DEFAULT_FORMAT)
ERB.new(format).result(binding)
end
alias_method :heroku, :rasgele
def ordered
rasgele(ORDERED_FORMAT)
end
def self.rasgele(options = { language: :en, format: DEFAULT_FORMAT })
new(options[:language]).rasgele(options[:format])
end
def self.ordered(language = :en)
new(language).ordered
end
end
if __FILE__ == $PROGRAM_NAME
if ARGV.empty?
puts Rasgele.rasgele
elsif ARGV.include? 'ordered'
puts Rasgele.ordered
else
$stderr.puts "Usage: #{$PROGRAM_NAME} [ordered]"
exit(1)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment