Sha256: 30211ad2e462e656335d36d90ee18309debf302118596e80e3ae7357b00010b3
Contents?: true
Size: 1.1 KB
Versions: 1
Compression:
Stored size: 1.1 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 class BigDecimal def as_json(options = {}) to_f end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
bootstripe-0.2.2 | lib/bootstripe/number_additions.rb |