module Boppers::Uptime::RelativeTime
Public Class Methods
call(from_time, to_time)
click to toggle source
# File lib/boppers/uptime/relative_time.rb, line 6 def self.call(from_time, to_time) seconds = (to_time - from_time).to_i return plural(seconds, "second") if seconds < 60 minutes = (seconds / 60).to_i return plural(minutes, "minute") if minutes < 60 hours = (minutes / 60).to_i return plural(hours, "hour") if hours < 24 days = (hours / 24).to_i plural(days, "day") end
plural(count, one, many = "
click to toggle source
# File lib/boppers/uptime/relative_time.rb, line 20 def self.plural(count, one, many = "#{one}s") if count == 1 "#{count} #{one}" else "#{count} #{many}" end end