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 Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(seconds) ⇒ 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.



10
11
12
# File 'lib/elastic_apm/config/duration.rb', line 10

def initialize(seconds)
  @seconds = seconds
end

Instance Attribute Details

#secondsObject

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.



14
15
16
# File 'lib/elastic_apm/config/duration.rb', line 14

def seconds
  @seconds
end

Class Method Details

.parse(str, default_unit:) ⇒ 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.



16
17
18
19
20
21
22
# File 'lib/elastic_apm/config/duration.rb', line 16

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