-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjob.rb
87 lines (76 loc) · 2.21 KB
/
job.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# encoding: utf-8
Camping.goes :Job
module Job::Controllers
class Index < R '/'
def get
render :index
end
end
class Small < R '/small' #5min - 1hr
def get
@duration = rand(12) * 5 + 5
render :result
end
end
class Medium < R '/medium' #1hr - 16hr
def get
@duration = rand(33) * 30 + 60
render :result
end
end
class Large < R '/large' #16hr - 60hr
def get
@duration = rand(45) * 60 + (16 * 60)
render :result
end
end
end
module Job::Helpers
def ddate(duration)
diff = (duration * 60)
out = []
if diff >= (60 * 60)
c = (diff / (60 * 60.0)).floor
out << "#{c} hour#{c != 1 ? 's' : ''}"
diff -= (60 * 60) while diff >= (60 * 60)
end
if diff >= 60
c = (diff / 60.0).floor
out << "#{c} minute#{c != 1 ? 's' : ''}"
end
out.join(' ')
end
end
module Job::Views
def layout
xhtml_transitional do
head do
title "Job length generator"
style :type => "text/css" do
%{
/* <![CDATA[ */
* { margin: 0; padding: 0; font-family: "Lucida Grande", Helvetica, Arial, sans-serif; font-size: 100%; }
body { background-color: #ffffff; color: #000000; text-align: center; padding: 1em; font-size: 150%; }
h1 { font-size: 160%; margin-bottom: 1em; }
p { margin-bottom: 1em; }
#footer { position: absolute; bottom: 0; left: 0; font-size: 50%; margin-bottom: 0; }
/* ]]> */
}
end
end
body do
h1 { "Job length generator" }
self << yield
p { "Pick a job size: #{a 'small', :href => R(Small)} #{a 'medium', :href => R(Medium)} #{a 'large', :href => R(Large)}." }
p.footer! { "Created by #{a "Brenton Fletcher", :href => "http://blog.bloople.net"} in #{File.stat(__FILE__).size} bytes of code. " +
"<a href='mailto:i@bloople.net'>Email me</a>! Powered by " +
"#{a "Ruby", :href => "http://ruby-lang.org"} on #{a "Camping", :href => "http://github.com/camping/camping/"}." }
end
end
end
def index
end
def result
p { ddate(@duration) }
end
end