Sha256: b7c04f70317a10563f84ac23031934bb5baeda6533c0f34e0a6d1b9dcc864ad7

Contents?: true

Size: 1.1 KB

Versions: 2

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 Range
  def random
    rand * (max - min) + min
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bootstripe-0.2.7 lib/bootstripe/number_additions.rb
bootstripe-0.2.6 lib/bootstripe/number_additions.rb