Class: Benchmark::Memory::Job::IOOutput::ComparisonFormatter

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/benchmark/memory/job/io_output/comparison_formatter.rb

Overview

Format a comparison for use with the IOOutput.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#rjust, scale

Constructor Details

#initialize(comparison) ⇒ ComparisonFormatter

Instantiate a formatter to output an comparison into an IO.

Parameters:



15
16
17
# File 'lib/benchmark/memory/job/io_output/comparison_formatter.rb', line 15

def initialize(comparison)
  @comparison = comparison
end

Instance Attribute Details

#comparisonReport::Comparison (readonly)

Returns The comparison to format.

Returns:



20
21
22
# File 'lib/benchmark/memory/job/io_output/comparison_formatter.rb', line 20

def comparison
  @comparison
end

Instance Method Details

#to_sString

Format comparison to a string to put on the output.

Returns:

  • (String)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/benchmark/memory/job/io_output/comparison_formatter.rb', line 25

def to_s
  return "" unless comparison.possible?

  output = StringIO.new
  best, *rest = comparison.entries
  rest = Array(rest)

  add_best_summary(best, output)

  rest.each do |entry|
    add_comparison(entry, best, output)
  end

  output.string
end