Module: RichUnits::Multiplers::Numeric
- Included in:
- Numeric
- Defined in:
- lib/richunits/multipliers.rb
Overview
Numeric Multipliers
Adds methods to Numeric to make working with magnitudes (kilo, mega, giga, milli, micro, etc.) as well as bits and bytes easier.
1.kilo #=> 1000
1.milli #=> 0.001
1.kibi #=> 1024
To display a value in a certain denomination, simply perform the inverse operation by placing the multiplier called on unit (1) in the denominator.
1000 / 1.kilo #=> 1
1024 / 1.kibi #=> 1
Instance Method Summary collapse
- #atto ⇒ Object
-
#bit ⇒ Object
Bits and Bytes.
- #bits ⇒ Object
- #byte ⇒ Object
- #bytes ⇒ Object
- #centi ⇒ Object
-
#deci ⇒ Object
SI Fractional.
-
#deka ⇒ Object
SI Multipliers.
- #exa ⇒ Object
- #exbi ⇒ Object
- #femto ⇒ Object
- #gibi ⇒ Object
- #giga ⇒ Object
- #hecto ⇒ Object
-
#kibi ⇒ Object
SI Binary.
- #kilo ⇒ Object
- #mebi ⇒ Object
- #mega ⇒ Object
- #micro ⇒ Object
- #milli ⇒ Object
- #nano ⇒ Object
- #pebi ⇒ Object
- #peta ⇒ Object
- #pico ⇒ Object
- #tebi ⇒ Object
- #tera ⇒ Object
Instance Method Details
#atto ⇒ Object
49 |
# File 'lib/richunits/multipliers.rb', line 49 def atto ; self.to_f / 1000000000000000000 ; end |
#bit ⇒ Object
Bits and Bytes
62 |
# File 'lib/richunits/multipliers.rb', line 62 def bit ; self ; end |
#bits ⇒ Object
63 |
# File 'lib/richunits/multipliers.rb', line 63 def bits ; self ; end |
#byte ⇒ Object
64 |
# File 'lib/richunits/multipliers.rb', line 64 def byte ; self * 8 ; end |
#bytes ⇒ Object
65 |
# File 'lib/richunits/multipliers.rb', line 65 def bytes ; self * 8 ; end |
#centi ⇒ Object
43 |
# File 'lib/richunits/multipliers.rb', line 43 def centi ; self.to_f / 100 ; end |
#deci ⇒ Object
SI Fractional
42 |
# File 'lib/richunits/multipliers.rb', line 42 def deci ; self.to_f / 10 ; end |
#deka ⇒ Object
SI Multipliers
31 |
# File 'lib/richunits/multipliers.rb', line 31 def deka ; self * 10 ; end |
#exa ⇒ Object
38 |
# File 'lib/richunits/multipliers.rb', line 38 def exa ; self * 1000000000000000000 ; end |
#exbi ⇒ Object
58 |
# File 'lib/richunits/multipliers.rb', line 58 def exbi ; self * 1024**6 ; end |
#femto ⇒ Object
48 |
# File 'lib/richunits/multipliers.rb', line 48 def femto ; self.to_f / 1000000000000000 ; end |
#gibi ⇒ Object
55 |
# File 'lib/richunits/multipliers.rb', line 55 def gibi ; self * 1024**3 ; end |
#giga ⇒ Object
35 |
# File 'lib/richunits/multipliers.rb', line 35 def giga ; self * 1000000000 ; end |
#hecto ⇒ Object
32 |
# File 'lib/richunits/multipliers.rb', line 32 def hecto ; self * 100 ; end |
#kibi ⇒ Object
SI Binary
53 |
# File 'lib/richunits/multipliers.rb', line 53 def kibi ; self * 1024 ; end |
#kilo ⇒ Object
33 |
# File 'lib/richunits/multipliers.rb', line 33 def kilo ; self * 1000 ; end |
#mebi ⇒ Object
54 |
# File 'lib/richunits/multipliers.rb', line 54 def mebi ; self * 1024**2 ; end |
#mega ⇒ Object
34 |
# File 'lib/richunits/multipliers.rb', line 34 def mega ; self * 1000000 ; end |
#micro ⇒ Object
45 |
# File 'lib/richunits/multipliers.rb', line 45 def micro ; self.to_f / 1000000 ; end |
#milli ⇒ Object
44 |
# File 'lib/richunits/multipliers.rb', line 44 def milli ; self.to_f / 1000 ; end |
#nano ⇒ Object
46 |
# File 'lib/richunits/multipliers.rb', line 46 def nano ; self.to_f / 1000000000 ; end |
#pebi ⇒ Object
57 |
# File 'lib/richunits/multipliers.rb', line 57 def pebi ; self * 1024**5 ; end |
#peta ⇒ Object
37 |
# File 'lib/richunits/multipliers.rb', line 37 def peta ; self * 1000000000000000 ; end |
#pico ⇒ Object
47 |
# File 'lib/richunits/multipliers.rb', line 47 def pico ; self.to_f / 1000000000000 ; end |
#tebi ⇒ Object
56 |
# File 'lib/richunits/multipliers.rb', line 56 def tebi ; self * 1024**4 ; end |
#tera ⇒ Object
36 |
# File 'lib/richunits/multipliers.rb', line 36 def tera ; self * 1000000000000 ; end |