Method: Numeric#human_bytes
- Defined in:
- lib/epitools/core_ext/numbers.rb
#human_bytes(decimals = 0) ⇒ Object Also known as: human_size
203 204 205 206 207 208 |
# File 'lib/epitools/core_ext/numbers.rb', line 203 def human_bytes(decimals=0) power = self.log(1024).floor base = 1024.0 ** power units = BYTE_SIZE_TABLE[power] "#{(self / base).round(decimals)}#{units}" end |