class SorbetProgress::Parser

Parse Sorbet's JSON metrics file.

Public Instance Methods

parse(json) click to toggle source
# File lib/sorbet_progress/parser.rb, line 16
def parse(json)
  transform(parse_json(json))
end

Private Instance Methods

parse_json(json) click to toggle source
# File lib/sorbet_progress/parser.rb, line 23
def parse_json(json)
  JSON.parse(json)
rescue JSON::ParserError => e
  raise Error.new(3, "Metrics file is not valid JSON: " + e.message)
end
transform(parsed) click to toggle source
# File lib/sorbet_progress/parser.rb, line 30
def transform(parsed)
  Metrics.new(
    parsed.
      fetch("metrics").
      map { |metric|
        next unless metric.key?("value")
        Metric.new(
          metric.fetch("name"),
          metric.fetch("value")
        )
      }.
      compact
  )
rescue KeyError => e
  raise Error.new(4, "Expected file to have key: metrics: " + e.message)
end