File: entry_serializer.rb

package info (click to toggle)
ruby-benchmark-memory 0.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 300 kB
  • sloc: ruby: 1,121; makefile: 7; sh: 4
file content (37 lines) | stat: -rw-r--r-- 955 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# frozen_string_literal: true

require 'benchmark/memory/held_results/serializer'
require 'benchmark/memory/held_results/measurement_serializer'
require 'benchmark/memory/report/entry'

module Benchmark
  module Memory
    class HeldResults
      # Serialize entrys for holding between runs.
      class EntrySerializer < Serializer
        # Convert a JSON hash into an Entry.
        #
        # @param hash [Hash] A JSON document hash.
        #
        # @return [Report::Entry]
        def load(hash)
          @object = Report::Entry.new(
            hash['item'],
            MeasurementSerializer.load(hash['measurement'])
          )
          self
        end

        # Convert the entry to a Hash.
        #
        # @return [Hash] The entry as a Hash.
        def to_h
          {
            item: object.label,
            measurement: MeasurementSerializer.new(object.measurement).to_h
          }
        end
      end
    end
  end
end