Module: BBLib::NumericEnhancements
- Defined in:
- lib/bblib/core/mixins/numeric_enhancements.rb
Overview
This module contains methods that are intended to be mixed in to Integer and Float classes. They mostly provide convenience methods.
Instance Method Summary collapse
-
#ago ⇒ Object
Returns the time x seconds ago from now (x == this number).
-
#from_now ⇒ Object
Returns the time x seconds ago from now (x == this number).
-
#spell_out(include_and: true) ⇒ Object
Converts a number to english (only language supported currently) For example, 501.spell_out returns ‘five hundred and one’.
-
#to_delimited_s(delim = ',') ⇒ Object
Convert this integer into a string with every three digits separated by a delimiter on the left side of the decimal.
Instance Method Details
#ago ⇒ Object
Returns the time x seconds ago from now (x == this number)
31 32 33 |
# File 'lib/bblib/core/mixins/numeric_enhancements.rb', line 31 def ago Time.now - self end |
#from_now ⇒ Object
Returns the time x seconds ago from now (x == this number)
36 37 38 |
# File 'lib/bblib/core/mixins/numeric_enhancements.rb', line 36 def from_now Time.now + self end |
#spell_out(include_and: true) ⇒ Object
Converts a number to english (only language supported currently) For example, 501.spell_out returns ‘five hundred and one’
18 19 20 |
# 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 = ',') ⇒ Object
Convert this integer into a string with every three digits separated by a delimiter on the left side of the decimal
24 25 26 27 28 |
# 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 |