Class: Numeric

Inherits:
Object
  • Object
show all
Defined in:
lib/core_ext/numeric_bytes.rb

Constant Summary collapse

KILOBYTE =
1024
MEGABYTE =
KILOBYTE * 1024
GIGABYTE =
MEGABYTE * 1024
TERABYTE =
GIGABYTE * 1024
PETABYTE =
TERABYTE * 1024
EXABYTE =
PETABYTE * 1024

Instance Method Summary collapse

Instance Method Details

#bytesObject Also known as: byte

Enables the use of byte calculations and declarations, like 45.bytes + 2.6.megabytes

2.bytes # => 2


40
41
42
# File 'lib/core_ext/numeric_bytes.rb', line 40

def bytes
  self
end

#exabytesObject Also known as: exabyte

Returns the number of bytes equivalent to the exabytes provided.

2.exabytes # => 2_305_843_009_213_693_952


88
89
90
# File 'lib/core_ext/numeric_bytes.rb', line 88

def exabytes
  self * EXABYTE
end

#gigabytesObject Also known as: gigabyte

Returns the number of bytes equivalent to the gigabytes provided.

2.gigabytes # => 2_147_483_648


64
65
66
# File 'lib/core_ext/numeric_bytes.rb', line 64

def gigabytes
  self * GIGABYTE
end

#kilobytesObject Also known as: kilobyte

Returns the number of bytes equivalent to the kilobytes provided.

2.kilobytes # => 2048


48
49
50
# File 'lib/core_ext/numeric_bytes.rb', line 48

def kilobytes
  self * KILOBYTE
end

#megabytesObject Also known as: megabyte

Returns the number of bytes equivalent to the megabytes provided.

2.megabytes # => 2_097_152


56
57
58
# File 'lib/core_ext/numeric_bytes.rb', line 56

def megabytes
  self * MEGABYTE
end

#petabytesObject Also known as: petabyte

Returns the number of bytes equivalent to the petabytes provided.

2.petabytes # => 2_251_799_813_685_248


80
81
82
# File 'lib/core_ext/numeric_bytes.rb', line 80

def petabytes
  self * PETABYTE
end

#terabytesObject Also known as: terabyte

Returns the number of bytes equivalent to the terabytes provided.

2.terabytes # => 2_199_023_255_552


72
73
74
# File 'lib/core_ext/numeric_bytes.rb', line 72

def terabytes
  self * TERABYTE
end