Class: Hoss::Config::Bytes Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hoss/config/bytes.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 Method Summary collapse

Constructor Details

#initialize(default_unit: 'kb') ⇒ Bytes

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



31
32
33
# File 'lib/hoss/config/bytes.rb', line 31

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

Instance Method Details

#call(value) ⇒ 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.



35
36
37
38
39
# File 'lib/hoss/config/bytes.rb', line 35

def call(value)
  _, amount, unit = REGEX.match(String(value)).to_a
  unit ||= @default_unit
  MULTIPLIERS.fetch(unit.downcase, 1) * amount.to_i
end