Sha256: daf69be62e19aafe74853a8d7026b9f3b453bb251ca4aa74a1ee73024ed2c551

Contents?: true

Size: 765 Bytes

Versions: 5

Compression:

Stored size: 765 Bytes

Contents

# typed: true
# frozen_string_literal: true

require "sorbet_progress/error"
require "sorbet_progress/metric"

module SorbetProgress
  # A collection of `Metric`s. Acts like a Hash, though sorbet actually gives
  # us an array.
  class Metrics
    extend T::Sig

    sig { params(array: T::Array[Metric]).void }
    def initialize(array)
      @array = array
    end

    sig { params(name: String).returns(T.nilable(Metric)) }
    def [](name)
      @array.find { |metric| metric.name == name }
    end

    sig { params(name: String).returns(Metric) }
    def fetch(name)
      result = @array.find { |metric| metric.name == name }
      if result.nil?
        raise Error.new(5, "Metric not found: " + name)
      else
        result
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sorbet-progress-0.2.4 lib/sorbet_progress/metrics.rb
sorbet-progress-0.2.3 lib/sorbet_progress/metrics.rb
sorbet-progress-0.2.2 lib/sorbet_progress/metrics.rb
sorbet-progress-0.2.1 lib/sorbet_progress/metrics.rb
sorbet-progress-0.2.0 lib/sorbet_progress/metrics.rb