Class: SorbetProgress::Metrics

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/sorbet_progress/metrics.rb

Overview

A collection of ‘Metric`s. Acts like a Hash, though sorbet actually gives us an array.

Instance Method Summary collapse

Constructor Details

#initialize(array) ⇒ Metrics

Returns a new instance of Metrics.



14
15
16
# File 'lib/sorbet_progress/metrics.rb', line 14

def initialize(array)
  @array = array
end

Instance Method Details

#[](name) ⇒ Object



19
20
21
# File 'lib/sorbet_progress/metrics.rb', line 19

def [](name)
  @array.find { |metric| metric.name == name }
end

#fetch(name) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/sorbet_progress/metrics.rb', line 24

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