Module: Spoom::Sorbet::MetricsParser
- Defined in:
- lib/spoom/sorbet/metrics.rb
Constant Summary collapse
- DEFAULT_PREFIX =
"ruby_typer.unknown."
Class Method Summary collapse
-
.parse_file(path, prefix = DEFAULT_PREFIX) ⇒ Object
: (String path, ?String prefix) -> Hash[String, Integer].
-
.parse_hash(obj, prefix = DEFAULT_PREFIX) ⇒ Object
: (Hash[String, untyped] obj, ?String prefix) -> Hash[String, Integer].
-
.parse_string(string, prefix = DEFAULT_PREFIX) ⇒ Object
: (String string, ?String prefix) -> Hash[String, Integer].
Class Method Details
.parse_file(path, prefix = DEFAULT_PREFIX) ⇒ Object
: (String path, ?String prefix) -> Hash[String, Integer]
13 14 15 |
# File 'lib/spoom/sorbet/metrics.rb', line 13 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) -> Hash[String, Integer]
23 24 25 26 27 28 29 |
# File 'lib/spoom/sorbet/metrics.rb', line 23 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
: (String string, ?String prefix) -> Hash[String, Integer]
18 19 20 |
# File 'lib/spoom/sorbet/metrics.rb', line 18 def parse_string(string, prefix = DEFAULT_PREFIX) parse_hash(JSON.parse(string), prefix) end |