forked from appdev-projects/sinatra-omnicalc-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
56 lines (41 loc) · 984 Bytes
/
app.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
require "sinatra"
require "sinatra/reloader"
get("/") do
redirect("/add")
end
get("/add") do
erb(:add_form)
end
get("/wizard_add") do
@first_num = params.fetch("first_num").to_f
@second_num = params.fetch("second_num").to_f
@result = @first_num + @second_num
erb(:add_result)
end
get("/subtract") do
erb(:subtraction_form)
end
get("/wizard_subtract") do
@first_num = params.fetch("first_num").to_f
@second_num = params.fetch("second_num").to_f
@result = @second_num - @first_num
erb(:sub_result)
end
get("/multiply") do
erb(:mult_form)
end
get("/wizard_multiply") do
@first_num = params.fetch("first_num").to_f
@second_num = params.fetch("second_num").to_f
@result = @second_num * @first_num
erb(:mult_result)
end
get("/divide") do
erb(:divform)
end
get("/wizard_divide") do
@first_num = params.fetch("first_num").to_f
@second_num = params.fetch("second_num").to_f
@result = @first_num / @second_num
erb(:div_result)
end