Class: UserSessionsPrinter
Constant Summary
Constants included from Constants
Constants::HOURS_NEEDED, Constants::SECRET_42, Constants::UID_42, Constants::URL_42
Instance Attribute Summary collapse
-
#pastel ⇒ Object
readonly
Returns the value of attribute pastel.
-
#user_sessions ⇒ Object
readonly
Returns the value of attribute user_sessions.
Instance Method Summary collapse
- #all ⇒ Object
-
#initialize(user_sessions) ⇒ UserSessionsPrinter
constructor
A new instance of UserSessionsPrinter.
- #sessions_this_week ⇒ Object
Constructor Details
#initialize(user_sessions) ⇒ UserSessionsPrinter
Returns a new instance of UserSessionsPrinter.
232 233 234 235 |
# File 'lib/ft_42.rb', line 232 def initialize(user_sessions) @pastel = Pastel.new @user_sessions = user_sessions end |
Instance Attribute Details
#pastel ⇒ Object (readonly)
Returns the value of attribute pastel.
230 231 232 |
# File 'lib/ft_42.rb', line 230 def pastel @pastel end |
#user_sessions ⇒ Object (readonly)
Returns the value of attribute user_sessions.
230 231 232 |
# File 'lib/ft_42.rb', line 230 def user_sessions @user_sessions end |
Instance Method Details
#all ⇒ Object
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/ft_42.rb', line 237 def all 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 pastel.red.bold("Warning: Logged in on more than one computer. Please logout from #{session.host} ASAP.") end active = true end end unless active puts "Was last active " + highlight("#{ActionView::Base.new.time_ago_in_words(user_sessions.sessions.first.end_at)} ago") + " at #{highlight(cluster(user_sessions.sessions.first.host))}." end end puts "Has " + highlight("#{hours} #{hours == 1 ? 'hour' : 'hours'}") + " in the clusters this week, starting #{Time.current.beginning_of_week.strftime("%A, %B #{Time.current.beginning_of_week.day.ordinalize}")}. #{'Go to sleep.' if hours > 60}" percent_complete = ((hours.to_f / HOURS_NEEDED.to_f) * 100).round if (percent_complete <= 100) = ProgressBar.create(progress_mark: "█", length: 60, format: "%t: |" + pastel.red("%B") + "| #{hours}/38 hours") percent_complete.times { .increment } puts end end |
#sessions_this_week ⇒ Object
267 268 269 270 271 272 273 |
# File 'lib/ft_42.rb', line 267 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 |