7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/wox/helpers/number_helper.rb', line 7
def bytes_to_human_size bytes, precision = 1
kb = 1024
mb = 1024 * kb
gb = 1024 * mb
case
when bytes < kb; "%d #{plural(bytes, 'byte', 'bytes')}" % bytes
when bytes < mb; "%.#{precision}f #{plural((bytes / kb), 'kilobyte', 'kilobytes')}" % (bytes / kb)
when bytes < gb; "%.#{precision}f #{plural((bytes / mb), 'megabyte', 'megabytes')}" % (bytes / mb)
when bytes >= gb; "%.#{precision}f #{plural((bytes / gb), 'gigabyte', 'gigabytes')}" % (bytes / gb)
end
end
|