Module: ImageOptim::Runner::Space
- Defined in:
- lib/image_optim/runner.rb
Constant Summary collapse
- SIZE_SYMBOLS =
%w[B K M G T P E].freeze
- PRECISION =
1
- LENGTH =
4 + PRECISION + 1
- EMPTY_SPACE =
' ' * LENGTH
Class Attribute Summary collapse
-
.base10 ⇒ Object
writeonly
Sets the attribute base10.
Class Method Summary collapse
Class Attribute Details
.base10=(value) ⇒ Object (writeonly)
Sets the attribute base10
21 22 23 |
# File 'lib/image_optim/runner.rb', line 21 def base10=(value) @base10 = value end |
Class Method Details
.denominator ⇒ Object
22 23 24 |
# File 'lib/image_optim/runner.rb', line 22 def denominator @denominator ||= @base10 ? 1000.0 : 1024.0 end |
.space(size) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/image_optim/runner.rb', line 26 def space(size) case size when 0, nil EMPTY_SPACE else log_denominator = Math.log(size) / Math.log(denominator) degree = [log_denominator.floor, SIZE_SYMBOLS.length - 1].min number = size / (denominator ** degree) "#{degree == 0 ? number.to_i : "%.#{PRECISION}f" % number}#{SIZE_SYMBOLS[degree]}".rjust(LENGTH) end end |