Sha256: c486a703651bbed2316d4aba4f309841889707cbac2b7fe1e0e7f44d774ead69
Contents?: true
Size: 929 Bytes
Versions: 1
Compression:
Stored size: 929 Bytes
Contents
class Numeric include ErrorHelper Alpha26 = ("a".."z").to_a def to_s26 return "" if self < 1 s, q = "", self loop do q, r = (q - 1).divmod(26) s.prepend(Alpha26[r]) break if q.zero? end s end def safe_part(part) if self > 0 if part >= 0 return part.to_f/self.to_f else raise_positive_number_only end elsif self == 0 return 0 else raise_positive_number_only end end def safe_percent(part) if self > 0 if part >= 0 return safe_part(part)*100 else raise_positive_number_only end elsif self == 0 return 0 else raise_positive_number_only end end def to_time_hash mm, ss = self.divmod(60) hh, mm = mm.divmod(60) dd, hh = hh.divmod(24) return { days: dd, hours: hh, minutes: mm, seconds: ss, } end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
creative_rails_utilities-0.3.3 | lib/creative_rails_utilities/numeric.rb |