ft_42 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ft_42.rb +60 -8
- metadata +9 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71640937d6e3a0f74345abea7b28ada0a807adf6
|
4
|
+
data.tar.gz: c854c7d10eeeaa4bff0f971edda7c38d5a8f3742
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd37dce0bdf0b793d0a0cf8dbd12365cd604463ecb1791877bbff4d801b6d1a5169279ad687595c65e57fda68d0873b5bf06dfbd17aa3fc1f845183d4cbd9d98
|
7
|
+
data.tar.gz: 4136ccac33a424ad45c635e07378204eb8c2ea83d8ac6f1f24a792197ad223af784d3ae492252e96f2a93bf295b0e383b6c19c1e8f3a526f8c22f7b500813d3f
|
data/lib/ft_42.rb
CHANGED
@@ -11,19 +11,22 @@ module Constants
|
|
11
11
|
HOURS_NEEDED = 38
|
12
12
|
end
|
13
13
|
|
14
|
-
class FT_42
|
15
14
|
|
15
|
+
class FT_42
|
16
16
|
def initialize(*args)
|
17
17
|
ft_42 = Client.new(args.first)
|
18
18
|
user = User.new(ft_42.user)
|
19
19
|
user_sessions = UserSessions.new(ft_42.user_sessions)
|
20
20
|
user_print = UserPrinter.new(user)
|
21
21
|
user_sessions_print = UserSessionsPrinter.new(user_sessions)
|
22
|
-
|
23
|
-
|
22
|
+
if args.size == 1
|
23
|
+
user_print.all
|
24
|
+
user_sessions_print.all
|
25
|
+
end
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
29
|
+
|
27
30
|
class Client
|
28
31
|
attr_reader :username, :token
|
29
32
|
|
@@ -53,6 +56,7 @@ class Client
|
|
53
56
|
end
|
54
57
|
end
|
55
58
|
|
59
|
+
|
56
60
|
class Token
|
57
61
|
include Constants
|
58
62
|
|
@@ -64,6 +68,8 @@ class Token
|
|
64
68
|
end
|
65
69
|
end
|
66
70
|
|
71
|
+
|
72
|
+
|
67
73
|
class User
|
68
74
|
attr_reader :user
|
69
75
|
|
@@ -128,6 +134,8 @@ class User
|
|
128
134
|
end
|
129
135
|
end
|
130
136
|
|
137
|
+
|
138
|
+
|
131
139
|
class Session
|
132
140
|
attr_reader :session
|
133
141
|
|
@@ -156,6 +164,8 @@ class Session
|
|
156
164
|
end
|
157
165
|
end
|
158
166
|
|
167
|
+
|
168
|
+
|
159
169
|
class UserSessions
|
160
170
|
attr_reader :user_sessions
|
161
171
|
|
@@ -176,6 +186,8 @@ class UserSessions
|
|
176
186
|
end
|
177
187
|
end
|
178
188
|
|
189
|
+
|
190
|
+
|
179
191
|
class UserPrinter
|
180
192
|
attr_reader :pastel, :user
|
181
193
|
|
@@ -224,6 +236,8 @@ class UserPrinter
|
|
224
236
|
end
|
225
237
|
end
|
226
238
|
|
239
|
+
|
240
|
+
|
227
241
|
class UserSessionsPrinter
|
228
242
|
include Constants
|
229
243
|
|
@@ -235,6 +249,11 @@ class UserSessionsPrinter
|
|
235
249
|
end
|
236
250
|
|
237
251
|
def all
|
252
|
+
active_or_last_active
|
253
|
+
hours_this_week
|
254
|
+
end
|
255
|
+
|
256
|
+
def active_or_last_active
|
238
257
|
unless user_sessions.sessions.empty?
|
239
258
|
active = false
|
240
259
|
user_sessions.sessions.each do |session|
|
@@ -243,22 +262,31 @@ class UserSessionsPrinter
|
|
243
262
|
puts "Is #{highlight('active')} at " + highlight("#{cluster(session.host)}") + " computer #{session.host}."
|
244
263
|
end
|
245
264
|
unless session.primary?
|
246
|
-
puts
|
265
|
+
puts warning("Warning: Logged in on more than one computer. Please logout from #{session.host} ASAP.")
|
247
266
|
end
|
248
267
|
active = true
|
249
268
|
end
|
250
269
|
end
|
251
270
|
|
252
271
|
unless active
|
253
|
-
|
272
|
+
last_active
|
254
273
|
end
|
255
|
-
end
|
274
|
+
end
|
275
|
+
end
|
256
276
|
|
257
|
-
|
277
|
+
def last_active
|
278
|
+
puts "Was last active " + last_active_time_ago + " at #{last_active_computer}."
|
279
|
+
end
|
280
|
+
|
281
|
+
def hours_this_week
|
282
|
+
puts "Has " + highlight("#{hours} #{hours_pluralize}") + " in the clusters this week, starting #{last_monday}. #{'Go to sleep.' if hours > 60}"
|
283
|
+
hours_progress_bar
|
284
|
+
end
|
258
285
|
|
286
|
+
def hours_progress_bar
|
259
287
|
percent_complete = ((hours.to_f / HOURS_NEEDED.to_f) * 100).round
|
260
288
|
if (percent_complete <= 100)
|
261
|
-
progressbar_needed = ProgressBar.create(progress_mark: "█", length: 60, format: "%t: |" +
|
289
|
+
progressbar_needed = ProgressBar.create(progress_mark: "█", length: 60, format: "%t: |" + warning("%B") + "| #{hours}/38 hours")
|
262
290
|
percent_complete.times { progressbar_needed.increment }
|
263
291
|
puts progressbar_needed
|
264
292
|
end
|
@@ -278,10 +306,22 @@ class UserSessionsPrinter
|
|
278
306
|
user_sessions.total_hours_this_week
|
279
307
|
end
|
280
308
|
|
309
|
+
def hours_pluralize
|
310
|
+
if hours == 1
|
311
|
+
"hour"
|
312
|
+
else
|
313
|
+
"hours"
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
281
317
|
def highlight(string)
|
282
318
|
pastel.bright_green.bold(string)
|
283
319
|
end
|
284
320
|
|
321
|
+
def warning(string)
|
322
|
+
pastel.red(string)
|
323
|
+
end
|
324
|
+
|
285
325
|
def cluster(host)
|
286
326
|
case true
|
287
327
|
when host.include?("z1") then "Cluster 1"
|
@@ -291,4 +331,16 @@ class UserSessionsPrinter
|
|
291
331
|
else host
|
292
332
|
end
|
293
333
|
end
|
334
|
+
|
335
|
+
def last_active_time_ago
|
336
|
+
highlight("#{ActionView::Base.new.time_ago_in_words(user_sessions.sessions.first.end_at)} ago")
|
337
|
+
end
|
338
|
+
|
339
|
+
def last_active_computer
|
340
|
+
highlight(cluster(user_sessions.sessions.first.host))
|
341
|
+
end
|
342
|
+
|
343
|
+
def last_monday
|
344
|
+
Time.current.beginning_of_week.strftime("%A, %B #{Time.current.beginning_of_week.day.ordinalize}")
|
345
|
+
end
|
294
346
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ft_42
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matias Fernandez
|
@@ -14,42 +14,30 @@ dependencies:
|
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '4.2'
|
20
|
-
- - ">="
|
17
|
+
- - '='
|
21
18
|
- !ruby/object:Gem::Version
|
22
|
-
version: 4.2.
|
19
|
+
version: 4.2.2
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '4.2'
|
30
|
-
- - ">="
|
24
|
+
- - '='
|
31
25
|
- !ruby/object:Gem::Version
|
32
|
-
version: 4.2.
|
26
|
+
version: 4.2.2
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: actionview
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
36
30
|
requirements:
|
37
|
-
- -
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: '4.2'
|
40
|
-
- - ">="
|
31
|
+
- - '='
|
41
32
|
- !ruby/object:Gem::Version
|
42
|
-
version: 4.2.
|
33
|
+
version: 4.2.2
|
43
34
|
type: :runtime
|
44
35
|
prerelease: false
|
45
36
|
version_requirements: !ruby/object:Gem::Requirement
|
46
37
|
requirements:
|
47
|
-
- -
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version: '4.2'
|
50
|
-
- - ">="
|
38
|
+
- - '='
|
51
39
|
- !ruby/object:Gem::Version
|
52
|
-
version: 4.2.
|
40
|
+
version: 4.2.2
|
53
41
|
- !ruby/object:Gem::Dependency
|
54
42
|
name: pastel
|
55
43
|
requirement: !ruby/object:Gem::Requirement
|