module BBLib::NumericEnhancements

This module contains methods that are intended to be mixed in to Integer and Float classes. They mostly provide convenience methods.

Public Instance Methods

ago() click to toggle source

Returns the time x seconds ago from now (x == this number)

# File lib/bblib/core/mixins/numeric_enhancements.rb, line 31
def ago
  Time.now - self
end
from_now() click to toggle source

Returns the time x seconds ago from now (x == this number)

# File lib/bblib/core/mixins/numeric_enhancements.rb, line 36
def from_now
  Time.now + self
end
spell_out(include_and: true) click to toggle source

Converts a number to english (only language supported currently) For example, 501.spell_out returns 'five hundred and one'

# File lib/bblib/core/mixins/numeric_enhancements.rb, line 18
def spell_out(include_and: true)
  BBLib.number_spelled_out(self, include_and: include_and)
end
to_delimited_s(delim = ',') click to toggle source

Convert this integer into a string with every three digits separated by a delimiter on the left side of the decimal

# File lib/bblib/core/mixins/numeric_enhancements.rb, line 24
def to_delimited_s(delim = ',')
  split = self.to_s.split('.')
  split[0] = split.first.reverse.gsub(/(\d{3})/, "\\1#{delim}").reverse
  split.join('.').uncapsulate(',')
end