Module: Spoom::Sorbet::Metrics::MetricsFileParser

Defined in:
lib/spoom/sorbet/metrics/metrics_file_parser.rb

Constant Summary collapse

DEFAULT_PREFIX =
"ruby_typer.unknown."

Class Method Summary collapse

Class Method Details

.parse_file(path, prefix = DEFAULT_PREFIX) ⇒ Object

: (String path, ?String prefix) -> Hash[String, Integer]



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

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

.parse_hash(obj, prefix = DEFAULT_PREFIX) ⇒ Object

: (Hash[String, untyped] obj, ?String prefix) -> Counters



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

def parse_hash(obj, prefix = DEFAULT_PREFIX)
  obj["metrics"].each_with_object(Counters.new) do |metric, metrics|
    name = metric["name"].sub(prefix, "")
    metrics[name] = metric["value"] || 0
  end
end

.parse_string(string, prefix = DEFAULT_PREFIX) ⇒ Object

: (String string, ?String prefix) -> Hash[String, Integer]



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

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