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
85 |
# File 'lib/richunits/multipliers.rb', line 85 def atto ; self.to_f / 1000000000000000000 ; end |
#bit ⇒ Object
Bits and Bytes
98 |
# File 'lib/richunits/multipliers.rb', line 98 def bit ; self ; end |
#bits ⇒ Object
99 |
# File 'lib/richunits/multipliers.rb', line 99 def bits ; self ; end |
#byte ⇒ Object
100 |
# File 'lib/richunits/multipliers.rb', line 100 def byte ; self * 8 ; end |
#bytes ⇒ Object
101 |
# File 'lib/richunits/multipliers.rb', line 101 def bytes ; self * 8 ; end |
#centi ⇒ Object
79 |
# File 'lib/richunits/multipliers.rb', line 79 def centi ; self.to_f / 100 ; end |
#deci ⇒ Object
SI Fractional
78 |
# File 'lib/richunits/multipliers.rb', line 78 def deci ; self.to_f / 10 ; end |
#deka ⇒ Object
SI Multipliers
67 |
# File 'lib/richunits/multipliers.rb', line 67 def deka ; self * 10 ; end |
#exa ⇒ Object
74 |
# File 'lib/richunits/multipliers.rb', line 74 def exa ; self * 1000000000000000000 ; end |
#exbi ⇒ Object
94 |
# File 'lib/richunits/multipliers.rb', line 94 def exbi ; self * 1024**6 ; end |
#femto ⇒ Object
84 |
# File 'lib/richunits/multipliers.rb', line 84 def femto ; self.to_f / 1000000000000000 ; end |
#gibi ⇒ Object
91 |
# File 'lib/richunits/multipliers.rb', line 91 def gibi ; self * 1024**3 ; end |
#giga ⇒ Object
71 |
# File 'lib/richunits/multipliers.rb', line 71 def giga ; self * 1000000000 ; end |
#hecto ⇒ Object
68 |
# File 'lib/richunits/multipliers.rb', line 68 def hecto ; self * 100 ; end |
#kibi ⇒ Object
SI Binary
89 |
# File 'lib/richunits/multipliers.rb', line 89 def kibi ; self * 1024 ; end |
#kilo ⇒ Object
69 |
# File 'lib/richunits/multipliers.rb', line 69 def kilo ; self * 1000 ; end |
#mebi ⇒ Object
90 |
# File 'lib/richunits/multipliers.rb', line 90 def mebi ; self * 1024**2 ; end |
#mega ⇒ Object
70 |
# File 'lib/richunits/multipliers.rb', line 70 def mega ; self * 1000000 ; end |
#micro ⇒ Object
81 |
# File 'lib/richunits/multipliers.rb', line 81 def micro ; self.to_f / 1000000 ; end |
#milli ⇒ Object
80 |
# File 'lib/richunits/multipliers.rb', line 80 def milli ; self.to_f / 1000 ; end |
#nano ⇒ Object
82 |
# File 'lib/richunits/multipliers.rb', line 82 def nano ; self.to_f / 1000000000 ; end |
#pebi ⇒ Object
93 |
# File 'lib/richunits/multipliers.rb', line 93 def pebi ; self * 1024**5 ; end |
#peta ⇒ Object
73 |
# File 'lib/richunits/multipliers.rb', line 73 def peta ; self * 1000000000000000 ; end |
#pico ⇒ Object
83 |
# File 'lib/richunits/multipliers.rb', line 83 def pico ; self.to_f / 1000000000000 ; end |
#tebi ⇒ Object
92 |
# File 'lib/richunits/multipliers.rb', line 92 def tebi ; self * 1024**4 ; end |
#tera ⇒ Object
72 |
# File 'lib/richunits/multipliers.rb', line 72 def tera ; self * 1000000000000 ; end |