/
fortune.rb
72 lines (59 loc) · 2.07 KB
/
fortune.rb
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
require 'rubygems'
require 'sinatra'
def getfortune(birthyear, wantsdirty)
fortunes=[
"You will make new friends this year",
"You will find yourself particularly lucky in the month of March",
"Play games often and you will be surprised how often you will win",
"Watch your mouth when your temper gets hot",
"You will have great success in many endeavors",
"You will receive money in the mail",
"You will have success in every aspect of your life",
"You will come up with the next great idea of this generation" ]
oldfortunes=[
"Your hip will break",
"Your viagara subscription may run out before you know it",
"You will be hospitalized within the next week for any number of reasons",
"You will find love but he or she will be toothless",
"Hold on, you are how old?" ]
dirtyendings=[
" in bed during the ride of your life",
" with your best friends mom",
" with great pride in your own private parts",
" with penis in thy ear",
" with more than one sex partner at the same time",
" but your lover will still cheat on you",
" and you will receive twice the amount of oral sex as usual",
" but its too bad you will get chlamydia from a stripper",
" but sometimes even a blow job won't help you succeed",
" but your private parts may not be as safe as you think they are",
" with sex toy in hand" ]
if birthyear < 1998
# person born before 1998
if birthyear < 1968
# person born before 1968. geezer!
fortunes = oldfortunes
end
if wantsdirty
# combine fortunes with dirty endings
fortunes = fortunes.zip(dirtyendings).map{|pair| pair.inject(:+)}
end
# pick a random fortune
fortunes[rand(fortunes.length)]
else
# person's a kid. set them straight.
"Read a book, kid"
end
end
before do
headers "Content-Type" => "text/html; charset=utf-8"
end
get '/' do
@title="Fortune Finder 1.0"
erb :form
end
post '/fortune' do
@title="Your fortune is revealed"
@fortune = getfortune(params[:birthyear].to_i, params[:dirtyfortune])
erb :fortune
end