Module: Numeric::Multipliers

Included in:
Numeric
Defined in:
lib/standard/facets/multipliers.rb

Overview

Numeric::Multipliers

Adds methods to Numeric to make working with magnitudes (kilo, mega, giga, milli, micro, etc.)

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

Thanks to Rich Kilmer and bytes.rb which inspired this library.

Instance Method Summary collapse

Instance Method Details

#atto ⇒ Object



43
# File 'lib/standard/facets/multipliers.rb', line 43

def atto  ; self.to_f / 1000000000000000000 ; end

#centi ⇒ Object



37
# File 'lib/standard/facets/multipliers.rb', line 37

def centi ; self.to_f / 100 ; end

#deci ⇒ Object

SI Fractional



36
# File 'lib/standard/facets/multipliers.rb', line 36

def deci  ; self.to_f / 10 ; end

#deka ⇒ Object

SI Multipliers



25
# File 'lib/standard/facets/multipliers.rb', line 25

def deka  ; self * 10 ; end

#exa ⇒ Object



32
# File 'lib/standard/facets/multipliers.rb', line 32

def exa   ; self * 1000000000000000000 ; end

#exbi ⇒ Object



52
# File 'lib/standard/facets/multipliers.rb', line 52

def exbi ; self * 1024**6 ; end

#femto ⇒ Object



42
# File 'lib/standard/facets/multipliers.rb', line 42

def femto ; self.to_f / 1000000000000000 ; end

#gibi ⇒ Object



49
# File 'lib/standard/facets/multipliers.rb', line 49

def gibi ; self * 1024**3 ; end

#giga ⇒ Object



29
# File 'lib/standard/facets/multipliers.rb', line 29

def giga  ; self * 1000000000 ; end

#hecto ⇒ Object



26
# File 'lib/standard/facets/multipliers.rb', line 26

def hecto ; self * 100 ; end

#kibi ⇒ Object

SI Binary



47
# File 'lib/standard/facets/multipliers.rb', line 47

def kibi ; self * 1024 ; end

#kilo ⇒ Object



27
# File 'lib/standard/facets/multipliers.rb', line 27

def kilo  ; self * 1000 ; end

#mebi ⇒ Object



48
# File 'lib/standard/facets/multipliers.rb', line 48

def mebi ; self * 1024**2 ; end

#mega ⇒ Object



28
# File 'lib/standard/facets/multipliers.rb', line 28

def mega  ; self * 1000000 ; end

#micro ⇒ Object



39
# File 'lib/standard/facets/multipliers.rb', line 39

def micro ; self.to_f / 1000000 ; end

#milli ⇒ Object



38
# File 'lib/standard/facets/multipliers.rb', line 38

def milli ; self.to_f / 1000 ; end

#nano ⇒ Object



40
# File 'lib/standard/facets/multipliers.rb', line 40

def nano  ; self.to_f / 1000000000 ; end

#pebi ⇒ Object



51
# File 'lib/standard/facets/multipliers.rb', line 51

def pebi ; self * 1024**5 ; end

#peta ⇒ Object



31
# File 'lib/standard/facets/multipliers.rb', line 31

def peta  ; self * 1000000000000000 ; end

#pico ⇒ Object



41
# File 'lib/standard/facets/multipliers.rb', line 41

def pico  ; self.to_f / 1000000000000 ; end

#tebi ⇒ Object



50
# File 'lib/standard/facets/multipliers.rb', line 50

def tebi ; self * 1024**4 ; end

#tera ⇒ Object



30
# File 'lib/standard/facets/multipliers.rb', line 30

def tera  ; self * 1000000000000 ; end