Sha256: 14997046f4b02abe58a9bd9c2457da7eddff4b5599cfdb360ee0f71fc4c2ab5d
Contents?: true
Size: 1.04 KB
Versions: 3
Compression:
Stored size: 1.04 KB
Contents
class Numeric def to_period(brief = false) 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 (!brief or days == 0) display = display + display_concat + "#{minutes}m" display_concat = ' ' end if seconds > 0 and (!brief or days == 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
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
bootstripe-0.2.5 | lib/bootstripe/number_additions.rb |
bootstripe-0.2.4 | lib/bootstripe/number_additions.rb |
bootstripe-0.2.3 | lib/bootstripe/number_additions.rb |