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
-
.parse_file(path, prefix = DEFAULT_PREFIX) ⇒ Object
Raises if ‘path` doesn’t point to a valid file that we have access to (see ‘File.read` for details) : (String path, ?String prefix) -> Hash[String, Integer].
-
.parse_hash(obj, prefix = DEFAULT_PREFIX) ⇒ Object
: (Hash[String, untyped] obj, ?String prefix) -> Counters.
-
.parse_string(string, prefix = DEFAULT_PREFIX) ⇒ Object
: (String string, ?String prefix) -> Hash[String, Integer].
Class Method Details
.parse_file(path, prefix = DEFAULT_PREFIX) ⇒ Object
Raises if ‘path` doesn’t point to a valid file that we have access to (see ‘File.read` for details) : (String path, ?String prefix) -> Hash[String, Integer]
15 16 17 |
# File 'lib/spoom/sorbet/metrics/metrics_file_parser.rb', line 15 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
25 26 27 28 29 30 |
# File 'lib/spoom/sorbet/metrics/metrics_file_parser.rb', line 25 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]
20 21 22 |
# File 'lib/spoom/sorbet/metrics/metrics_file_parser.rb', line 20 def parse_string(string, prefix = DEFAULT_PREFIX) parse_hash(JSON.parse(string), prefix) end |