Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- 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)
-
- (Object) bytes
(also: #byte)
Enables the use of byte calculations and declarations, like 45.bytes + 2.6.megabytes.
-
- (Object) commas
Return a string representation of this value with commas between the thousands groupings.
- - (Object) exabytes (also: #exabyte, #eb)
- - (Object) gigabytes (also: #gigabyte, #gb)
- - (Object) kilobytes (also: #kilobyte, #kb)
- - (Object) megabytes (also: #megabyte, #mb)
- - (Object) petabytes (also: #petabyte, #pb)
- - (Object) terabytes (also: #terabyte, #tb)
Instance Method Details
- (Object) bytes 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 |
- (Object) commas
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 |
- (Object) exabytes Also known as: exabyte, eb
41 42 43 |
# File 'lib/babushka/core_patches/bytes.rb', line 41 def exabytes self * EXABYTE end |
- (Object) gigabytes Also known as: gigabyte, gb
26 27 28 |
# File 'lib/babushka/core_patches/bytes.rb', line 26 def gigabytes self * GIGABYTE end |
- (Object) kilobytes Also known as: kilobyte, kb
16 17 18 |
# File 'lib/babushka/core_patches/bytes.rb', line 16 def kilobytes self * KILOBYTE end |
- (Object) megabytes Also known as: megabyte, mb
21 22 23 |
# File 'lib/babushka/core_patches/bytes.rb', line 21 def megabytes self * MEGABYTE end |
- (Object) petabytes Also known as: petabyte, pb
36 37 38 |
# File 'lib/babushka/core_patches/bytes.rb', line 36 def petabytes self * PETABYTE end |
- (Object) terabytes Also known as: terabyte, tb
31 32 33 |
# File 'lib/babushka/core_patches/bytes.rb', line 31 def terabytes self * TERABYTE end |