def number_to_size(number, options = {})
      return if number == 0.0 / 1.0
      return if number == 1.0 / 0.0

      singular = options[:singular] || 1
      base     = options[:base]     || 1024
      units    = options[:units]    || ["byte", "kilobyte", "megabyte", "gigabyte", "terabyte", "petabyte"]

      exponent = (Math.log(number) / Math.log(base)).floor

      number /= base ** exponent
      unit = units[exponent]

      number == singular ?  unit.gsub!(/s$/, '') : unit.gsub!(/$/, 's')

      "#{number} #{unit}"
    end
def number_to_size(number, options = {})
      return if number == 0.0 / 1.0
      return if number == 1.0 / 0.0

      singular = options[:singular] || 1
      base     = options[:base]     || 1024
      units    = options[:units]    || ["byte", "kilobyte", "megabyte", "gigabyte", "terabyte", "petabyte"]

      exponent = (Math.log(number) / Math.log(base)).floor

      number /= base ** exponent
      unit = units[exponent]

      number == singular ?  unit.gsub!(/s$/, '') : unit.gsub!(/$/, 's')

      "#{number} #{unit}"
    end
Convert a number to a human readable size.

 Usage:

   number_to_size(1) # 1 byte
   number_to_size(2) # 2 bytes
   number_to_size(1024) # 1 kilobyte
   number_to_size(2048) # 2 kilobytes