Class: Benchmark::Memory::Job::IOOutput::EntryFormatter

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

Overview

Format entries for use with the IOOutput.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#rjust, scale

Constructor Details

#initialize(entry) ⇒ EntryFormatter

Instantiate a formatter to output an entry into an IO.

Parameters:

  • entry (Entry)

    The entry to format.



18
19
20
# File 'lib/benchmark/memory/job/io_output/entry_formatter.rb', line 18

def initialize(entry)
  @entry = entry
end

Instance Attribute Details

#entryEntry (readonly)

Returns The entry to format.

Returns:

  • (Entry)

    The entry to format.



23
24
25
# File 'lib/benchmark/memory/job/io_output/entry_formatter.rb', line 23

def entry
  @entry
end

Instance Method Details

#to_sString

Format entry to a string to put on the output.

Returns:

  • (String)


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

def to_s
  output = StringIO.new
  output << rjust(entry.label)

  first, *rest = *entry.measurement

  output << "#{MetricFormatter.new(first)}\n"
  rest.each do |metric|
    output << "#{' ' * 20}#{MetricFormatter.new(metric)}\n"
  end

  output.string
end