Module: Diskman::System
- Defined in:
- lib/diskman/system.rb
Class Method Summary collapse
-
.bytes2human(b) ⇒ Object
Convert bytes into a human-friendly representation.
-
.exec!(cmd, safe: true) ⇒ Object
Execute a command.
Class Method Details
.bytes2human(b) ⇒ Object
Convert bytes into a human-friendly representation.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/diskman/system.rb', line 13 def self.bytes2human(b) return '0B' if b <= 0 # Use 1000 to match the misleading way disk capacities are advertised. k = 1000 suffixes = %w[T G M K B] suffixes.each_with_index do |suffix, i| threshold = k ** (suffixes.length - i - 1) if b >= threshold return (b / threshold).to_s + suffix end end end |