lib/middleman-webp/converter.rb in middleman-webp-0.4.2 vs lib/middleman-webp/converter.rb in middleman-webp-0.4.3
- old
+ new
@@ -111,10 +111,10 @@
# number_to_human_size(12345)
# # => '12.06 KiB'
#
# Returns string containing size and unit.
def number_to_human_size(n)
- return '0 B' if n == 0
+ return "#{n} B" if n <= 0
units = %w(B KiB MiB GiB TiB PiB)
exponent = (Math.log(n) / Math.log(1024)).to_i
format("%g #{units[exponent]}",
format('%.2f', n.to_f / 1024**exponent))