Sha256: e25d1fc909dc09542ec07ab08b8a543406bf39a111a9fcdc204af75d12d80281
Contents?: true
Size: 646 Bytes
Versions: 8
Compression:
Stored size: 646 Bytes
Contents
#!/usr/bin/env ruby # -*- encoding: utf-8 -*- # Copyright Steffi Dorn <mail@muflax.com>, 2017 # License: GNU APGLv3 (or later) <http://www.gnu.org/copyleft/gpl.html> class Numeric def round_into num ((self / num) / num + 1) * num end def round_to num (self / num.to_f).round * num end def multiple_of?(number) number != 0 ? self % number == 0 : zero? end DELIMITER_REGEX = /(\d)(?=(\d\d\d)+(?!\d))/ def delimit delimiter="_" left, right = self.to_s.split(".") left.gsub!(DELIMITER_REGEX) do |digit_to_delimit| "#{digit_to_delimit}#{delimiter}" end [left, right].compact.join(".") end end
Version data entries
8 entries across 8 versions & 1 rubygems