Class: ElasticAPM::Config::Duration Private

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_apm/config/duration.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

MULTIPLIERS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{ 'ms' => 0.001, 'm' => 60 }.freeze
REGEX =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

/^(-)?(\d+)(m|ms|s)?$/i.freeze

Instance Method Summary collapse

Constructor Details

#initialize(default_unit: 's') ⇒ Duration

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Duration.



27
28
29
# File 'lib/elastic_apm/config/duration.rb', line 27

def initialize(default_unit: 's')
  @default_unit = default_unit
end

Instance Method Details

#call(str) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



31
32
33
34
35
36
37
# File 'lib/elastic_apm/config/duration.rb', line 31

def call(str)
  _, negative, amount, unit = REGEX.match(String(str)).to_a
  unit ||= @default_unit
  seconds = MULTIPLIERS.fetch(unit.downcase, 1) * amount.to_i
  seconds = 0 - seconds if negative
  seconds
end