Sha256: 772e5e26d9b60c5b87899852c5b915b784dca9e4bd3ecf4c020f05982e97e626
Contents?: true
Size: 590 Bytes
Versions: 17
Compression:
Stored size: 590 Bytes
Contents
# frozen_string_literal: true module ElasticAPM class Config # @api private class Duration MULTIPLIERS = { 'ms' => 0.001, 'm' => 60 }.freeze REGEX = /^(-)?(\d+)(m|ms|s)?$/i.freeze def initialize(seconds) @seconds = seconds end attr_accessor :seconds def self.parse(str, default_unit:) _, negative, amount, unit = REGEX.match(str).to_a unit ||= default_unit seconds = MULTIPLIERS.fetch(unit.downcase, 1) * amount.to_i seconds = 0 - seconds if negative new(seconds) end end end end
Version data entries
17 entries across 17 versions & 1 rubygems