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