Class: Numeric

Inherits:
Object show all
Defined in:
lib/babushka/core_patches/bytes.rb,
lib/babushka/core_patches/numeric.rb

Overview

Lifted from activesupport-3.0.5/lib/active_support/core_ext/numeric/bytes.rb

Constant Summary

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



11
12
13
# File 'lib/babushka/core_patches/bytes.rb', line 11

def bytes
  self
end

#commasObject

Return a string representation of this value with commas between the thousands groupings. Some examples: 3.commas #=> “3” 314.commas #=> “314” 31459.commas #=> “31,459”



8
9
10
11
12
13
14
15
# File 'lib/babushka/core_patches/numeric.rb', line 8

def commas
  if self < 1000
    to_s
  else
    whole, fract = self.to_s.split('.')
    [ whole.reverse.scan(/\d{1,3}/).join(',').reverse, fract ].squash.join('.')
  end
end

#exabytesObject Also known as: exabyte, eb



41
42
43
# File 'lib/babushka/core_patches/bytes.rb', line 41

def exabytes
  self * EXABYTE
end

#gigabytesObject Also known as: gigabyte, gb



26
27
28
# File 'lib/babushka/core_patches/bytes.rb', line 26

def gigabytes
  self * GIGABYTE
end

#kilobytesObject Also known as: kilobyte, kb



16
17
18
# File 'lib/babushka/core_patches/bytes.rb', line 16

def kilobytes
  self * KILOBYTE
end

#megabytesObject Also known as: megabyte, mb



21
22
23
# File 'lib/babushka/core_patches/bytes.rb', line 21

def megabytes
  self * MEGABYTE
end

#petabytesObject Also known as: petabyte, pb



36
37
38
# File 'lib/babushka/core_patches/bytes.rb', line 36

def petabytes
  self * PETABYTE
end

#terabytesObject Also known as: terabyte, tb



31
32
33
# File 'lib/babushka/core_patches/bytes.rb', line 31

def terabytes
  self * TERABYTE
end