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.
466
467
468
469
|
# File 'lib/ft_42.rb', line 466
def initialize(user_sessions)
@pastel = Pastel.new
@user_sessions = user_sessions
end
|
Instance Attribute Details
#pastel ⇒ Object
Returns the value of attribute pastel.
464
465
466
|
# File 'lib/ft_42.rb', line 464
def pastel
@pastel
end
|
#user_sessions ⇒ Object
Returns the value of attribute user_sessions.
464
465
466
|
# File 'lib/ft_42.rb', line 464
def user_sessions
@user_sessions
end
|
Instance Method Details
#active_or_last_active ⇒ Object
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
|
# File 'lib/ft_42.rb', line 492
def active_or_last_active
unless user_sessions.sessions.empty?
active = false
user_sessions.sessions.each do |session|
unless session.end_at.nil?
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
end
unless active
last_active
end
end
end
|
#all ⇒ Object
471
472
473
474
|
# File 'lib/ft_42.rb', line 471
def all
active_or_last_active
hours_this_week
end
|
#hours_progress_bar ⇒ Object
530
531
532
533
534
535
536
537
538
539
|
# File 'lib/ft_42.rb', line 530
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
541
542
543
544
545
546
547
548
549
550
|
# File 'lib/ft_42.rb', line 541
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
552
553
554
555
556
557
558
559
560
561
|
# File 'lib/ft_42.rb', line 552
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
519
520
521
522
|
# File 'lib/ft_42.rb', line 519
def hours_this_week
puts "Has " + highlight("#{hours} #{hours_pluralize}") + " in the clusters this week, starting #{last_monday}."
end
|
#last_active ⇒ Object
515
516
517
|
# File 'lib/ft_42.rb', line 515
def last_active
puts "Was last active " + (last_active_time_ago || "") + " at #{last_active_computer}."
end
|
#progress_bar ⇒ Object
524
525
526
527
528
|
# File 'lib/ft_42.rb', line 524
def progress_bar
hours_progress_bar
hours_progress_bar_achievement
hours_progress_bar_challenge
end
|
#sessions ⇒ Object
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
|
# File 'lib/ft_42.rb', line 476
def sessions
unless user_sessions.sessions.empty?
user_sessions.sessions.each do |session|
session_start = "Session start: " + session.begin_at.to_time.strftime("%A, %B %d at %I:%M:%S %p")
session_end = "Session end: " + session.end_at.to_time.strftime("%A, %B %d at %I:%M:%S %p")
duration_in_hours = ActiveSupport::NumberHelper.number_to_rounded((session.end_at.to_time - session.begin_at.to_time) / 60 / 60, :precision => 2)
puts
puts "Session duration: " + highlight("#{duration_in_hours} hours")
puts session_start
puts session_end
puts "Session host: " + session.host + " at " + cluster(session.host)
end
puts
end
end
|
#sessions_this_week ⇒ Object
563
564
565
566
567
568
569
|
# File 'lib/ft_42.rb', line 563
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
|