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.



16
17
18
# File 'lib/benchmark/memory/job/io_output/entry_formatter.rb', line 16

def initialize(entry)
  @entry = entry
end

Instance Attribute Details

#entryEntry (readonly)

Returns The entry to format.

Returns:

  • (Entry)

    The entry to format.



21
22
23
# File 'lib/benchmark/memory/job/io_output/entry_formatter.rb', line 21

def entry
  @entry
end

Instance Method Details

#to_sString

Format entry to a string to put on the output.

Returns:

  • (String)


26
27
28
29
30
31
32
33
34
35
# File 'lib/benchmark/memory/job/io_output/entry_formatter.rb', line 26

def to_s
  output = StringIO.new
  output << rjust(entry.label)
  entry.measurement.each_with_index.map do |metric, index|
    output << " " * 20 unless index == 0
    output << MetricFormatter.new(metric)
    output << "\n"
  end
  output.string
end