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

Instance Method Details

#attoObject



85
# File 'lib/richunits/multipliers.rb', line 85

def atto  ; self.to_f / 1000000000000000000 ; end

#bitObject

Bits and Bytes



98
# File 'lib/richunits/multipliers.rb', line 98

def bit   ; self ; end

#bitsObject



99
# File 'lib/richunits/multipliers.rb', line 99

def bits  ; self ; end

#byteObject



100
# File 'lib/richunits/multipliers.rb', line 100

def byte  ; self * 8 ; end

#bytesObject



101
# File 'lib/richunits/multipliers.rb', line 101

def bytes ; self * 8 ; end

#centiObject



79
# File 'lib/richunits/multipliers.rb', line 79

def centi ; self.to_f / 100 ; end

#deciObject

SI Fractional



78
# File 'lib/richunits/multipliers.rb', line 78

def deci  ; self.to_f / 10 ; end

#dekaObject

SI Multipliers



67
# File 'lib/richunits/multipliers.rb', line 67

def deka  ; self * 10 ; end

#exaObject



74
# File 'lib/richunits/multipliers.rb', line 74

def exa   ; self * 1000000000000000000 ; end

#exbiObject



94
# File 'lib/richunits/multipliers.rb', line 94

def exbi ; self * 1024**6 ; end

#femtoObject



84
# File 'lib/richunits/multipliers.rb', line 84

def femto ; self.to_f / 1000000000000000 ; end

#gibiObject



91
# File 'lib/richunits/multipliers.rb', line 91

def gibi ; self * 1024**3 ; end

#gigaObject



71
# File 'lib/richunits/multipliers.rb', line 71

def giga  ; self * 1000000000 ; end

#hectoObject



68
# File 'lib/richunits/multipliers.rb', line 68

def hecto ; self * 100 ; end

#kibiObject

SI Binary



89
# File 'lib/richunits/multipliers.rb', line 89

def kibi ; self * 1024 ; end

#kiloObject



69
# File 'lib/richunits/multipliers.rb', line 69

def kilo  ; self * 1000 ; end

#mebiObject



90
# File 'lib/richunits/multipliers.rb', line 90

def mebi ; self * 1024**2 ; end

#megaObject



70
# File 'lib/richunits/multipliers.rb', line 70

def mega  ; self * 1000000 ; end

#microObject



81
# File 'lib/richunits/multipliers.rb', line 81

def micro ; self.to_f / 1000000 ; end

#milliObject



80
# File 'lib/richunits/multipliers.rb', line 80

def milli ; self.to_f / 1000 ; end

#nanoObject



82
# File 'lib/richunits/multipliers.rb', line 82

def nano  ; self.to_f / 1000000000 ; end

#pebiObject



93
# File 'lib/richunits/multipliers.rb', line 93

def pebi ; self * 1024**5 ; end

#petaObject



73
# File 'lib/richunits/multipliers.rb', line 73

def peta  ; self * 1000000000000000 ; end

#picoObject



83
# File 'lib/richunits/multipliers.rb', line 83

def pico  ; self.to_f / 1000000000000 ; end

#tebiObject



92
# File 'lib/richunits/multipliers.rb', line 92

def tebi ; self * 1024**4 ; end

#teraObject



72
# File 'lib/richunits/multipliers.rb', line 72

def tera  ; self * 1000000000000 ; end