public
Created

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
# Turn a PEG on its head! Generate some compliments.
 
class Complimenter
def compliments
phrases
end
 
def phrases
phrase + ". " + maybe { phrases }
end
 
def phrase
pick_one(
-> { you_make_me },
-> { you_have_a },
-> { you_have },
-> { i_love_you },
-> { when_i_am },
-> { you_are }
)
end
 
def you_are
"You are" + adverbs + adjective
end
 
def when_i_am
"When I am " + bad_emotion + " you " + pick_me_up + emphatic
end
 
def pick_me_up
pick_one("cheer me up", "kick my ass into gear", "put the wind back in my sails")
end
 
def bad_emotion
pick_one("sad", "down", "upset", "freaking out", "in the lost-and-found", "throwing a tantrum")
end
 
def i_love_you
"I love you"
end
 
def you_make_me
"You make me" + maybe { adverbs } + verb + maybe(0.25) { adverbs } + emphatic
end
 
def you_have
"You have" + adjectives + plural_attribute + emphatic
end
 
def you_have_a
"You have a" + adjectives + singular_attribute + emphatic
end
 
def emphatic
maybe(0.95) {
", " +
pick_one(
"really",
"you really do",
"you do",
-> { "I swear" + maybe {" it" } },
-> { maybe { "up" } + "on my grandmother's grave" },
"by Jove",
"you don't even know",
"seriously",
"I mean it"
) +
maybe(0.3) { emphatic }
}
end
 
def adjectives
adjective + maybe(0.25) { adjectives }
end
 
def adjective
" " + pick_one("beautiful", "glorious", "wonderful", "wiggly")
end
 
def plural_attribute
" " + pick_one("eyes", "ears", "fingers", "thumbs", "toes", "feet", "nostrils", "hair")
end
 
def singular_attribute
" " + pick_one("voice", "nose", "face", "sense of humor", "poise", "grace", "mind", "heart", "soul", "laugh")
end
 
def adverbs
adverb + maybe(0.25) { adverbs }
end
 
def adverb
" " + pick_one("with happiness", "ecstatically", "beautifully", "gloriously")
end
 
def verb
" " + pick_one("swoon", "dance", "sing", "be a better person")
end
 
def pick_one(*items)
chosen = items.sample
if chosen.respond_to?(:call)
chosen.call
else
chosen
end
end
 
def maybe(p=0.5)
rand < p ? yield : ''
end
end
 
 
complimenter = Complimenter.new
compliment = complimenter.compliments
puts compliment
puts compliment.size
`say "#{compliment}"`
 
# Uncomment at your own risk:
# mega_compliment = Array.new(300) { complimenter.compliments }.join(". ")
# puts mega_compliment
# `say #{mega_compliment.gsub("'", "")}`

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.