Class: UserSessionsPrinter
- Inherits:
-
Object
- Object
- UserSessionsPrinter
show all
- Includes:
- Constants
- Defined in:
- lib/ft_42.rb
Constant Summary
Constants included
from Constants
Constants::HOURS_ACHIEVEMENT, Constants::HOURS_CHALLENGE, Constants::HOURS_NEEDED, Constants::SECRET_42, Constants::UID_42, Constants::URL_42
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of UserSessionsPrinter.
248
249
250
251
|
# File 'lib/ft_42.rb', line 248
def initialize(user_sessions)
@pastel = Pastel.new
@user_sessions = user_sessions
end
|
Instance Attribute Details
#pastel ⇒ Object
Returns the value of attribute pastel.
246
247
248
|
# File 'lib/ft_42.rb', line 246
def pastel
@pastel
end
|
#user_sessions ⇒ Object
Returns the value of attribute user_sessions.
246
247
248
|
# File 'lib/ft_42.rb', line 246
def user_sessions
@user_sessions
end
|
Instance Method Details
#active_or_last_active ⇒ Object
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
# File 'lib/ft_42.rb', line 258
def active_or_last_active
unless user_sessions.sessions.empty?
active = false
user_sessions.sessions.each do |session|
if session.end_at - session.begin_at == 600.0
unless active
puts "Is #{highlight('active')} at " + highlight("#{cluster(session.host)}") + " computer #{session.host}."
end
unless session.primary?
puts warning("Warning: Logged in on more than one computer. Please logout from #{session.host} ASAP.")
end
active = true
end
end
unless active
last_active
end
end
end
|
#all ⇒ Object
253
254
255
256
|
# File 'lib/ft_42.rb', line 253
def all
active_or_last_active
hours_this_week
end
|
#hours_progress_bar ⇒ Object
290
291
292
293
294
295
296
297
298
299
|
# File 'lib/ft_42.rb', line 290
def hours_progress_bar
percent_complete = ((hours.to_f / HOURS_NEEDED.to_f) * 100).round
if (percent_complete <= 100)
progressbar_needed = ProgressBar.create(progress_mark: "█", length: 64, format: "%t: |" + warning("%B") + "| #{hours}/38 hours")
percent_complete.times { progressbar_needed.increment }
print "Minimum "
print progressbar_needed
puts
end
end
|
#hours_progress_bar_achievement ⇒ Object
301
302
303
304
305
306
307
308
309
310
|
# File 'lib/ft_42.rb', line 301
def hours_progress_bar_achievement
percent_complete = ((hours.to_f / HOURS_ACHIEVEMENT.to_f) * 100).round
if (percent_complete <= 100)
progressbar_needed = ProgressBar.create(progress_mark: "█", length: 60, format: "%t: |" + warning("%B") + "| #{hours}/90 hours")
percent_complete.times { progressbar_needed.increment }
print "Achievement "
print progressbar_needed
puts
end
end
|
#hours_progress_bar_challenge ⇒ Object
312
313
314
315
316
317
318
319
320
321
|
# File 'lib/ft_42.rb', line 312
def hours_progress_bar_challenge
percent_complete = ((hours.to_f / HOURS_CHALLENGE.to_f) * 100).round
if (percent_complete <= 100)
progressbar_needed = ProgressBar.create(progress_mark: "█", length: 63, format: "%t: |" + warning("%B") + "| #{hours}/100 hours")
percent_complete.times { progressbar_needed.increment }
print "Challenge "
print progressbar_needed
puts
end
end
|
#hours_this_week ⇒ Object
283
284
285
286
287
288
|
# File 'lib/ft_42.rb', line 283
def hours_this_week
puts "Has " + highlight("#{hours} #{hours_pluralize}") + " in the clusters this week, starting #{last_monday}."
hours_progress_bar
hours_progress_bar_achievement
hours_progress_bar_challenge
end
|
#last_active ⇒ Object
279
280
281
|
# File 'lib/ft_42.rb', line 279
def last_active
puts "Was last active " + last_active_time_ago + " at #{last_active_computer}."
end
|
#sessions_this_week ⇒ Object
323
324
325
326
327
328
329
|
# File 'lib/ft_42.rb', line 323
def sessions_this_week
unless user_sessions.sessions.empty?
user_sessions.sessions.each do |session|
puts "#{session.host} from #{session.begin_at} to #{session.end_at}"
end
end
end
|