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

Version Path
elastic-apm-2.9.1 lib/elastic_apm/config/duration.rb
elastic-apm-2.9.0 lib/elastic_apm/config/duration.rb
elastic-apm-2.8.1 lib/elastic_apm/config/duration.rb
elastic-apm-2.8.0 lib/elastic_apm/config/duration.rb
elastic-apm-2.7.0 lib/elastic_apm/config/duration.rb
elastic-apm-2.6.1 lib/elastic_apm/config/duration.rb
elastic-apm-2.6.0 lib/elastic_apm/config/duration.rb
elastic-apm-2.5.0 lib/elastic_apm/config/duration.rb
elastic-apm-2.4.0 lib/elastic_apm/config/duration.rb
elastic-apm-2.3.1 lib/elastic_apm/config/duration.rb
elastic-apm-2.3.0 lib/elastic_apm/config/duration.rb
elastic-apm-2.2.0 lib/elastic_apm/config/duration.rb
elastic-apm-2.1.2 lib/elastic_apm/config/duration.rb
elastic-apm-2.1.1 lib/elastic_apm/config/duration.rb
elastic-apm-2.1.0 lib/elastic_apm/config/duration.rb
elastic-apm-2.0.1 lib/elastic_apm/config/duration.rb
elastic-apm-2.0.0 lib/elastic_apm/config/duration.rb