Class: UserSessionsPrinter

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/ft_42.rb

Constant Summary

Constants included from Constants

Constants::HOURS_NEEDED, Constants::SECRET_42, Constants::UID_42, Constants::URL_42

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_sessions) ⇒ UserSessionsPrinter

Returns a new instance of UserSessionsPrinter.



246
247
248
249
# File 'lib/ft_42.rb', line 246

def initialize(user_sessions)
  @pastel = Pastel.new
  @user_sessions = user_sessions
end

Instance Attribute Details

#pastelObject (readonly)

Returns the value of attribute pastel.



244
245
246
# File 'lib/ft_42.rb', line 244

def pastel
  @pastel
end

#user_sessionsObject (readonly)

Returns the value of attribute user_sessions.



244
245
246
# File 'lib/ft_42.rb', line 244

def user_sessions
  @user_sessions
end

Instance Method Details

#active_or_last_activeObject



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/ft_42.rb', line 256

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

#allObject



251
252
253
254
# File 'lib/ft_42.rb', line 251

def all
  active_or_last_active
  hours_this_week
end

#hours_progress_barObject



286
287
288
289
290
291
292
293
# File 'lib/ft_42.rb', line 286

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: 60, format: "%t: |" + warning("%B") + "| #{hours}/38 hours")
    percent_complete.times { progressbar_needed.increment }
    puts progressbar_needed
  end
end

#hours_this_weekObject



281
282
283
284
# File 'lib/ft_42.rb', line 281

def hours_this_week
  puts "Has " + highlight("#{hours} #{hours_pluralize}") + " in the clusters this week, starting #{last_monday}. #{'Go to sleep.' if hours > 60}"
  hours_progress_bar
end

#last_activeObject



277
278
279
# File 'lib/ft_42.rb', line 277

def last_active
  puts "Was last active " + last_active_time_ago + " at #{last_active_computer}."
end

#sessions_this_weekObject



295
296
297
298
299
300
301
# File 'lib/ft_42.rb', line 295

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