class Numeric
Constants
- Alpha26
Public Instance Methods
safe_part(part)
click to toggle source
# File lib/creative_rails_utilities/numeric.rb, line 18 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
safe_per(parts)
click to toggle source
# File lib/creative_rails_utilities/numeric.rb, line 46 def safe_per(parts) return 0 if self == 0 || parts == 0 return self.to_f/parts.to_f end
safe_percent(part, precision: 15)
click to toggle source
# File lib/creative_rails_utilities/numeric.rb, line 32 def safe_percent(part, precision: 15) if self > 0 if part >= 0 return (safe_part(part)*100).round(precision) else raise_positive_number_only end elsif self == 0 return 0 else raise_positive_number_only end end
to_s26()
click to toggle source
# File lib/creative_rails_utilities/numeric.rb, line 6 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
to_time_hash()
click to toggle source
# File lib/creative_rails_utilities/numeric.rb, line 52 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