Class: Filesize
- Inherits:
-
Object
- Object
- Filesize
- Defined in:
- lib/main2.rb
Class Method Summary collapse
Class Method Details
.size(size) ⇒ Object
247 248 249 250 251 252 253 254 255 |
# File 'lib/main2.rb', line 247 def self.size(size) units = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'Pib', 'EiB'] return '0.0 B' if size == 0 exp = (Math.log(size) / Math.log(1024)).to_i exp = 6 if exp > 6 '%.1f %s' % [size.to_f / 1024 ** exp, units[exp]] end |