Sha256: 4aff11faec8a2569a9afda30f9f0642b5f2c5f68f454cfb4377a40d576d7efb7
Contents?: true
Size: 992 Bytes
Versions: 17
Compression:
Stored size: 992 Bytes
Contents
# typed: strict # frozen_string_literal: true require_relative "sigils" module Spoom module Sorbet module MetricsParser extend T::Sig DEFAULT_PREFIX = "ruby_typer.unknown.." sig { params(path: String, prefix: String).returns(T::Hash[String, Integer]) } def self.parse_file(path, prefix = DEFAULT_PREFIX) parse_string(File.read(path), prefix) end sig { params(string: String, prefix: String).returns(T::Hash[String, Integer]) } def self.parse_string(string, prefix = DEFAULT_PREFIX) parse_hash(JSON.parse(string), prefix) end sig { params(obj: T::Hash[String, T.untyped], prefix: String).returns(T::Hash[String, Integer]) } def self.parse_hash(obj, prefix = DEFAULT_PREFIX) obj["metrics"].each_with_object(Hash.new(0)) do |metric, metrics| name = metric["name"] name = name.sub(prefix, '') metrics[name] = metric["value"] || 0 end end end end end
Version data entries
17 entries across 17 versions & 1 rubygems