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

Version Path
spoom-1.1.11 lib/spoom/sorbet/metrics.rb
spoom-1.1.10 lib/spoom/sorbet/metrics.rb
spoom-1.1.9 lib/spoom/sorbet/metrics.rb
spoom-1.1.8 lib/spoom/sorbet/metrics.rb
spoom-1.1.7 lib/spoom/sorbet/metrics.rb
spoom-1.1.6 lib/spoom/sorbet/metrics.rb
spoom-1.1.5 lib/spoom/sorbet/metrics.rb
spoom-1.1.4 lib/spoom/sorbet/metrics.rb
spoom-1.1.3 lib/spoom/sorbet/metrics.rb
spoom-1.1.2 lib/spoom/sorbet/metrics.rb
spoom-1.1.1 lib/spoom/sorbet/metrics.rb
spoom-1.1.0 lib/spoom/sorbet/metrics.rb
spoom-1.0.9 lib/spoom/sorbet/metrics.rb
spoom-1.0.8 lib/spoom/sorbet/metrics.rb
spoom-1.0.7 lib/spoom/sorbet/metrics.rb
spoom-1.0.6 lib/spoom/sorbet/metrics.rb
spoom-1.0.5 lib/spoom/sorbet/metrics.rb