Sha256: aa236d1ba9347f0a636f7c96c13959a66cd4fe7ffc10c9809fc21cacac498f74

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

#--
# Credit goes to Richard Kilmer for a great idea.
# And thanks to Ruby On Rails for making these readily available.
# And finally thanks to Alexander Kellett for suggesting Facet's offer them.
#++

class Numeric

  # Converts bits to bytes.
  def bits
    self / 8.0
  end

  # 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.)
  def bytes
    self
  end
  alias :byte :bytes

  # Converts kilobytes to bytes.
  def kilobytes
    self * 1024
  end
  alias :kilobyte :kilobytes
  alias :kb :kilobytes

  # Converts megabytes to bytes.
  def megabytes
    self * 1024.kilobytes
  end
  alias :megabyte :megabytes
  alias :mb :megabytes

  # Converts gigabytes to bytes.
  def gigabytes
    self * 1024.megabytes 
  end
  alias :gigabyte :gigabytes
  alias :gb :gigabytes

  # Converts terabytes to bytes.
  def terabytes
    self * 1024.gigabytes
  end
  alias :terabyte :terabytes
  alias :tb :terabytes

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
facets-0.6.3 lib/facet/numeric/bytes.rb