class Mastermind::Oscar::TimeManager

Attributes

start[R]
stop[R]

Public Instance Methods

evaluate(x,y) click to toggle source
# File lib/mastermind/oscar/time_manager.rb, line 29
def evaluate(x,y)
  [x / y, x % y] 
end
get_seconds() click to toggle source
# File lib/mastermind/oscar/time_manager.rb, line 33
def get_seconds
  stop - start
end
get_time(secs = get_seconds) click to toggle source
# File lib/mastermind/oscar/time_manager.rb, line 13
def get_time(secs = get_seconds)
  secs = secs.to_i
  days, secs = evaluate(secs, 86400)
  hour, secs = evaluate(secs, 3600)
  min, secs  = evaluate(secs, 60)

  string = []
  string << to_string(days, 'day')
  string << to_string(hour, 'hour')
  string << to_string(min, 'minute')
  string << to_string(secs, 'second')
  
  string.select!{|x| !x.nil?}
  string.join(", ")
end
start_timer() click to toggle source
# File lib/mastermind/oscar/time_manager.rb, line 5
def start_timer
  @start = Time.now
end
stop_timer() click to toggle source
# File lib/mastermind/oscar/time_manager.rb, line 9
def stop_timer
  @stop = Time.now
end
to_string(time, unit) click to toggle source
# File lib/mastermind/oscar/time_manager.rb, line 37
def to_string(time, unit)
  return if time == 0

  time > 1 ? s = 's' : s = ''
  "#{time} #{unit}#{s}"
end