module Megabytes

A tiny byte size formatter for when you don’t need or do not want to use ActiveSupport.

Constants

PAIRS
VERSION

Public Instance Methods

megabytes(bytes) click to toggle source

Returns a formatted byte count for easy reading. Bytes are counted using the 1024 quantifier.

@param bytes the number of bytes to display @return [String] the formatted size in kilo/mega/giga/tera/whatever bytes

# File lib/megabytes.rb, line 18
def megabytes(bytes)
  PAIRS.each_pair { |e, s| return [(bytes.to_f / (s / 1024)).round(2), e].join if bytes < s }
end