Class: Perfer::MeasurementsFormatter

Inherits:
Object
  • Object
show all
Includes:
Formatter
Defined in:
lib/perfer/formatter/measurements_formatter.rb

Constant Summary collapse

SEPARATOR =
'  '

Constants included from Formatter

Formatter::TIME_UNITS

Instance Method Summary collapse

Methods included from Formatter

#float_scale, #format_duration, #format_duration_and_error, #format_error, #format_float, #format_ips, #format_n, #format_time, #max_length_of, #ruby_version, #short_ruby_description

Constructor Details

#initialize(measurements) ⇒ MeasurementsFormatter

Returns a new instance of MeasurementsFormatter.



7
8
9
10
11
12
13
# File 'lib/perfer/formatter/measurements_formatter.rb', line 7

def initialize(measurements)
  @measurements = measurements
  @fields = Perfer::TIMES_FIELDS.dup
  @fields.reject! { |field|
    measurements.none? { |m| m.key? field }
  }
end

Instance Method Details

#reportObject



15
16
17
18
19
20
# File 'lib/perfer/formatter/measurements_formatter.rb', line 15

def report
  puts @fields.map { |field| field.to_s.center(8) }.join(SEPARATOR).rstrip
  @measurements.each { |m|
    puts @fields.map { |field| format_duration(m[field] || 0) }.join(SEPARATOR)
  }
end