Class: Numeric

Inherits:
Object
  • Object
show all
Defined in:
lib/s3streambackup/units.rb

Constant Summary collapse

UNITS =
%w{bytes KiB MiB GiB TiB PiB EiB}

Instance Method Summary collapse

Instance Method Details

#in_bytes_autoObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/s3streambackup/units.rb', line 3

def in_bytes_auto
  size = self.to_f
  units = UNITS.dup

  while size > 999
    size /= 1024
    units.shift
  end

  if units.length == UNITS.length
    "#{'%d' % size} #{units.first}"
  else
    "#{'%.1f' % size} #{units.first}"
  end
end