Skip to content

Instantly share code, notes, and snippets.

@syntruth
Created May 18, 2010 20:02
Show Gist options
  • Save syntruth/405465 to your computer and use it in GitHub Desktop.
Save syntruth/405465 to your computer and use it in GitHub Desktop.
def replace_in_plot(plot)
terms = @terms.dup()
plot.gsub!(/(:\w+)/) do |match|
key = match.sub(/:/, "").downcase.to_sym()
if terms.has_key?(key)
case terms[key]
when String
# The gsub prevents recursive calls.
term = replace_in_plot(term[key].gsub(/:#{key}/, ""))
when Array
if terms[key].length.zero?
term = "(#{NOT_ENOUGH % key})"
else
n = rand(terms[key].length())
term = terms[key].delete_at(n)
end
else
term = "(#{UNKNOWN % key})"
end
else
term = "(#{NO_GROUP % key})"
end
term
end
plot = handle_aan(plot)
plot = handle_cap(plot)
return plot
end
plots = [
"!cap! !aan! :noun tries to find !aan! :color :noun while in :location.",
"Running away from !aan! :adjective :noun, !aan! :noun finds love in :location.",
"Despite dealing with !aan! :color :noun, !aan! :adjective :noun ends up being !aan! :noun!"
]
terms = {
:verb => [
"run",
"fall",
"- eat",
"- jump",
"- scream",
"- bounce",
"- dance",
"- talk",
"- program"
],
:adjective => [
"big",
"intense",
"excited",
"nervous",
"confused",
"lost",
"fruit flavored"
]
:noun => [
"dog",
"cat",
"bird",
"plane",
"boy",
"girl",
"car",
"truck",
"computer",
"picture",
"paper",
"wheel"
],
:color => [
"red",
"blue",
"green",
"yellow",
"purple",
"orange",
"white",
"black",
"azure"
],
:location => [
"Paris",
"New York City",
"the moon",
"school",
"convent",
"Timbuktu",
"department of motor vehicles",
"toy factory",
"bookstore",
"grocery store"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment