Class: RegoValidate::Profiler::ByteFormatter
- Inherits:
-
Object
- Object
- RegoValidate::Profiler::ByteFormatter
- Defined in:
- lib/ruby/rego/cli.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.
538 539 540 541 |
# File 'lib/ruby/rego/cli.rb', line 538 def initialize(bytes) @sign = bytes.negative? ? "-" : "+" @size = bytes.abs end |
Instance Method Details
#render ⇒ Object
543 544 545 546 547 548 549 550 551 552 |
# File 'lib/ruby/rego/cli.rb', line 543 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 |