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 16 |
# File 'lib/babushka/core_patches/numeric.rb', line 8 def commas Babushka::LogHelpers.deprecated! '2017-09-01' if self < 1000 to_s else whole, fract = self.to_s.split('.') [ whole.reverse.scan(/\d{1,3}/).join(',').reverse, fract ].compact.join('.') end end |
#exabytes ⇒ Object Also known as: exabyte, eb
46 47 48 49 |
# File 'lib/babushka/core_patches/bytes.rb', line 46 def exabytes Babushka::LogHelpers.deprecated! '2017-09-01' self * EXABYTE end |
#gigabytes ⇒ Object Also known as: gigabyte, gb
28 29 30 31 |
# File 'lib/babushka/core_patches/bytes.rb', line 28 def gigabytes Babushka::LogHelpers.deprecated! '2017-09-01' self * GIGABYTE end |
#kilobytes ⇒ Object Also known as: kilobyte, kb
16 17 18 19 |
# File 'lib/babushka/core_patches/bytes.rb', line 16 def kilobytes Babushka::LogHelpers.deprecated! '2017-09-01' self * KILOBYTE end |
#megabytes ⇒ Object Also known as: megabyte, mb
22 23 24 25 |
# File 'lib/babushka/core_patches/bytes.rb', line 22 def megabytes Babushka::LogHelpers.deprecated! '2017-09-01' self * MEGABYTE end |
#petabytes ⇒ Object Also known as: petabyte, pb
40 41 42 43 |
# File 'lib/babushka/core_patches/bytes.rb', line 40 def petabytes Babushka::LogHelpers.deprecated! '2017-09-01' self * PETABYTE end |
#terabytes ⇒ Object Also known as: terabyte, tb
34 35 36 37 |
# File 'lib/babushka/core_patches/bytes.rb', line 34 def terabytes Babushka::LogHelpers.deprecated! '2017-09-01' self * TERABYTE end |