Created
November 15, 2011 02:42
-
-
Save illbzo1/1365967 to your computer and use it in GitHub Desktop.
Random Phrase Generator, Refactored
This file contains hidden or 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
require 'yaml' | |
words = YAML::load(File.open('words.yml')) | |
loop do | |
puts "Generate new phrase? (y / n)" | |
input = gets.chomp() | |
unless input == "n" | |
new_phrase = %w[adj2 noun].map { |type| words[type].sample } | |
addition = rand(7) | |
new_phrase.unshift(words['adj1'].sample) if addition > 2 | |
new_phrase.push(words['suffix'].sample) if addition <= 2 | |
new_phrase.unshift(words['prefix'].sample) if addition >= 6 | |
new_phrase = new_phrase.join(' ').split(' ') | |
new_phrase = new_phrase.each_with_index.map do |word, i| | |
if [0, new_phrase.size - 1].include?(i) || !['the', 'of', 'for'].include?(word) | |
word.capitalize | |
else | |
word | |
end | |
end.join(' ') | |
puts new_phrase | |
else | |
break | |
end | |
end | |
This file contains hidden or 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
adj1: | |
- super | |
- hyper | |
- ultra | |
- virtual | |
- ultimate | |
- legendary | |
- unforgettable | |
- mystical | |
adj2: | |
- robotic | |
- unruly | |
- dangerous | |
- nasty | |
- cursed | |
- rude | |
- deep space | |
- renegade | |
- fearsome | |
- mysterious | |
- magical | |
- karate | |
- kung-fu | |
noun: | |
- turtle | |
- wombat | |
- showdown | |
- action squad | |
- wizard | |
- polar bear | |
- detective | |
- operative | |
- werewolf | |
- fighter | |
- warrior | |
- dragon | |
prefix: | |
- legend of the | |
- return of the | |
- cooking with the | |
- revenge of the | |
- battle of the | |
- quest of the | |
- secret of the | |
- tournament of the | |
- clash of the | |
- adventures of the | |
- learn to read with the | |
suffix: | |
- jr. | |
- racing | |
- kart | |
- big game hunter | |
- skeet shooting | |
- strikes back | |
- the revenge | |
- back for more | |
- surf's up | |
- safari | |
- world tour | |
- beach volleyball |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment