Class: ElasticAPM::Config::Size Private

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_apm/config/size.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.

{
  'kb' => 1024,
  'mb' => 1024 * 1_000,
  'gb' => 1024 * 100_000
}.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+)(b|kb|mb|gb)?$/i.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bytes) ⇒ Size

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 Size.



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

def initialize(bytes)
  @bytes = bytes
end

Instance Attribute Details

#bytesObject

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.



18
19
20
# File 'lib/elastic_apm/config/size.rb', line 18

def bytes
  @bytes
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.



20
21
22
23
24
25
# File 'lib/elastic_apm/config/size.rb', line 20

def self.parse(str, default_unit:)
  _, amount, unit = REGEX.match(str).to_a
  unit ||= default_unit
  bytes = MULTIPLIERS.fetch(unit.downcase, 1) * amount.to_i
  new(bytes)
end