Class: RegoValidate::Profiler::ByteFormatter
- Inherits:
-
Object
- Object
- RegoValidate::Profiler::ByteFormatter
- Defined in:
- lib/ruby/rego/cli/profiling.rb
Overview
Formats byte sizes for profiler output.
Instance Method Summary collapse
-
#initialize(bytes) ⇒ ByteFormatter
constructor
A new instance of ByteFormatter.
-
#render ⇒ Object
Constructor Details
#initialize(bytes) ⇒ ByteFormatter
Returns a new instance of ByteFormatter.
40 41 42 43 |
# File 'lib/ruby/rego/cli/profiling.rb', line 40 def initialize(bytes) @sign = bytes.negative? ? "-" : "+" @size = bytes.abs end |
Instance Method Details
#render ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ruby/rego/cli/profiling.rb', line 45 def render unit, value = if size < 1024 ["B", size.to_s] elsif size < 1024 * 1024 ["KB", Kernel.format("%.2f", size / 1024.0)] else ["MB", Kernel.format("%.2f", size / (1024.0 * 1024.0))] end "#{sign}#{value} #{unit}" end |