Class: RubyScriptExporter::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_script_exporter/formatter.rb

Instance Method Summary collapse

Constructor Details

#initialize(measurements) ⇒ Formatter

Returns a new instance of Formatter.



4
5
6
# File 'lib/ruby_script_exporter/formatter.rb', line 4

def initialize(measurements)
  @measurements = measurements
end

Instance Method Details

#formatObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ruby_script_exporter/formatter.rb', line 8

def format
  output = []

  @measurements
    .group_by(&:measurement)
    .sort_by { |key, _| key }
    .map do |type, measurements|
      type = Type.from_name(type)
      output << type.format_for_open_metrics

      measurements.each do |measurement|
        output << measurement.format_as_open_metric
      end
    end

  output.join("\n")
end