mirror of
https://github.com/chromebrew/chromebrew.git
synced 2026-01-09 15:37:56 -05:00
* Rename IgnoredPatterns to AllowedPatterns. * Exclude docopt.rb (not our code) from Rubocop * Disable Style/RedundantReturn * Disable Style/MutableConstant * Disable Style/NumericLiterals * Set Layout/IndentationStyle to spaces * Temporarily disable various cops. * Add Rubocop CI via Octocop * Lint tree with rubocop -A -c .rubocop.yml Co-authored-by: Satadru Pramanik <satadru@gmail.com>
23 lines
483 B
Ruby
23 lines
483 B
Ruby
def human_size(bytes)
|
|
kilobyte = 1024.0
|
|
megabyte = kilobyte * kilobyte
|
|
gigabyte = megabyte * kilobyte
|
|
if bytes < kilobyte
|
|
units = 'B'
|
|
size = bytes
|
|
end
|
|
if (bytes >= kilobyte) && (bytes < megabyte)
|
|
units = 'KB'
|
|
size = bytes / kilobyte
|
|
end
|
|
if (bytes >= megabyte) && (bytes < gigabyte)
|
|
units = 'MB'
|
|
size = bytes / megabyte
|
|
end
|
|
if bytes >= gigabyte
|
|
units = 'GB'
|
|
size = bytes / gigabyte
|
|
end
|
|
return format('%.2f %s', size, units)
|
|
end
|