Class Numeric
In: lib/facet/float/round.rb
lib/facet/numeric/octet_units.rb
lib/facet/numeric/distance.rb
lib/facet/numeric/bytes.rb
lib/facet/numeric/succ.rb
lib/facet/numeric/to_b.rb
lib/facet/numeric/times.rb
lib/facet/numeric/bound_by.rb
Parent: Object

Methods

after   ago   approx?   at_least   at_most   before   bits   bound_by   byte   bytes   cmp   day   days   distance   fortnight   fortnights   from_now   gb   gigabyte   gigabytes   hour   hours   kb   kilobyte   kilobytes   later   mb   megabyte   megabytes   microsecond   microseconds   millisecond   milliseconds   minute   minutes   month   months   octet_units   pred   round_at   round_to   second   seconds   since   succ   tb   terabyte   terabytes   to_b   until   week   weeks   year   years  

Public Instance methods

Calculates time after a given time. Default time is now. Reads best with argument: 10.minutes.after(time)

ago(time = ::Time.now)

Alias for before

Returns the lower of self or x.

  require 'facet/numeric/bound_by'

  4.at_least(5)  #=> 5
  6.at_least(5)  #=> 6

Returns the greater of self or x.

  require 'facet/numeric/bound_by'

  4.at_most(5)  #=> 4
  6.at_most(5)  #=> 5

Calculates time before a given time. Default time is now. Reads best with arguments: 10.days.before( Time.now - 1.day )

Converts bits to bytes.

Returns the value or the given upper or lower bound if the value falls outside of them.

  require 'facet/comparable/bound_by'

  4.bound_by(2,7)  #=> 4
  9.bound_by(2,7)  #=> 7
  1.bound_by(2,7)  #=> 2
byte()

Alias for bytes

Enables the use of byte calculations and declarations, like 45.bytes + 2.6.megabytes. The base unit for all of these Numeric bytes methods is bytes. (One might expect it to be bits, but that doesn’t seem to be the general consensus.)

Alternate for comparison operator #<=>.

  require 'facet/numeric/succ'

  3.cmp(1)   #=>  1
  3.cmp(3)   #=>  0
  3.cmp(10)  #=> -1
day()

Alias for days

Converts days into seconds.

Returns the distance between self an another value. This is the same as #- but it provides an alternative for common naming between variant classes.

  require 'facet/numeric/distance'

  4.distance(3)  #=> 1
fortnight()

Alias for fortnights

Converts fortnights into seconds. (A fortnight is 2 weeks)

from_now(time = ::Time.now)

Alias for after

gb()

Alias for gigabytes

gigabyte()

Alias for gigabytes

Converts gigabytes to bytes.

hour()

Alias for hours

Converts hours into seconds.

kb()

Alias for kilobytes

kilobyte()

Alias for kilobytes

Converts kilobytes to bytes.

later(time = ::Time.now)

Alias for after

mb()

Alias for megabytes

megabyte()

Alias for megabytes

Converts megabytes to bytes.

microsecond()

Alias for microseconds

Converts microseconds into a fraction of seconds.

millisecond()

Alias for milliseconds

Converts milliseconds into a fraction of seconds.

minute()

Alias for minutes

Converts minutes into seconds.

month()

Alias for months

Converts months into seconds. WARNING: This is not exact as it assumes 30 days to a month.

Provides formated output of bytes proportial size.

  require 'facet/numeric/octet_units'

  1024.octet_units            #=> "1.00 KB"
  1048576.octet_units         #=> "1.00 MB"
  1073741824.octet_units      #=> "1.00 GB"
  1099511627776.octet_units   #=> "1.00 TB"

Takes a format string to adjust output.

  1024.octet_units('%.0f')    #=> "1 KB"

Note: the name of this method will likely change in the future. But the best name has yet to be determined at this point.

Provides pred as the opposite of succ.

  require 'facet/numeric/succ'

  3.pred(2)  #=> 1
second()

Alias for seconds

Enables the use of time calculations and declarations, like 45.minutes + 2.hours + 4.years. The base unit for all of these Numeric time methods is seconds.

since(time = ::Time.now)

Alias for after

Allows succ to take n increments.

  require 'facet/numeric/succ'

  3.succ(2)  #=> 5
tb()

Alias for terabytes

terabyte()

Alias for terabytes

Converts terabytes to bytes.

Provides a boolean interpretation of self. If self == 0 then false else true.

  require 'facet/numeric/to_b'

  0.to_b    #=> false
  1.to_b    #=> true
  2.3.to_b  #=> true
until(time = ::Time.now)

Alias for before

week()

Alias for weeks

Converts weeks into seconds.

year()

Alias for years

Converts years into seconds.

[Validate]