Module: Spoom::Sorbet::MetricsParser

Extended by:
T::Sig
Defined in:
lib/spoom/sorbet/metrics.rb

Constant Summary collapse

DEFAULT_PREFIX =
"ruby_typer.unknown.."

Class Method Summary collapse

Class Method Details

.parse_file(path, prefix = DEFAULT_PREFIX) ⇒ Object



15
16
17
# File 'lib/spoom/sorbet/metrics.rb', line 15

def parse_file(path, prefix = DEFAULT_PREFIX)
  parse_string(File.read(path), prefix)
end

.parse_hash(obj, prefix = DEFAULT_PREFIX) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/spoom/sorbet/metrics.rb', line 25

def 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

.parse_string(string, prefix = DEFAULT_PREFIX) ⇒ Object



20
21
22
# File 'lib/spoom/sorbet/metrics.rb', line 20

def parse_string(string, prefix = DEFAULT_PREFIX)
  parse_hash(JSON.parse(string), prefix)
end