Class: DeleteDerivedData::Filesize
- Inherits:
-
Object
- Object
- DeleteDerivedData::Filesize
- Defined in:
- lib/delete_derived_data/utils.rb
Class Method Summary collapse
Class Method Details
.dirSize(path) ⇒ Object
4 5 6 |
# File 'lib/delete_derived_data/utils.rb', line 4 def self.dirSize(path) File.size(path) + Dir["#{path}/**/*"].select { |f| File.file?(f) }.sum { |f| File.size(f) } end |
.size(size) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/delete_derived_data/utils.rb', line 8 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 |