Sha256: 42f39dded9553e056361732156d283b05b2c7cf484d2a910eec5aaba202163ae
Contents?: true
Size: 1.13 KB
Versions: 4
Compression:
Stored size: 1.13 KB
Contents
class Numeric def to_period(detailed = true) total_seconds = self.to_i days = total_seconds / 86400 hours = (total_seconds / 3600) - (days * 24) minutes = (total_seconds / 60) - (hours * 60) - (days * 1440) seconds = total_seconds % 60 display = '' display_concat = '' if days > 0 display = display + display_concat + "#{days}d" display_concat = ' ' end if hours > 0 display = display + display_concat + "#{hours}h" display_concat = ' ' end if minutes > 0 and (detailed or days == 0) display = display + display_concat + "#{minutes}m" display_concat = ' ' end if seconds > 0 and (detailed or (days == 0 and hours == 0)) display = display + display_concat + "#{seconds}s" end display end def to_formatted_time return '00:00' if self == 0 minutes = (self / 60).floor seconds = (self % 60).round minutes = '0' + minutes.to_s if minutes.to_s.length == 1 seconds = '0' + seconds.to_s if seconds.to_s.length == 1 "#{minutes}:#{seconds}" end end class Range def random rand * (max - min) + min end end
Version data entries
4 entries across 4 versions & 1 rubygems