Module: VV::IntegerMethods

Included in:
Integer
Defined in:
lib/vv/integer_methods.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
# File 'lib/vv/integer_methods.rb', line 4

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#bitsObject



24
25
26
27
# File 'lib/vv/integer_methods.rb', line 24

def bits
  bits_per_byte = 8
  self.ceil_divide bits_per_byte
end

#ceil_divide(divisor) ⇒ Object



20
21
22
# File 'lib/vv/integer_methods.rb', line 20

def ceil_divide divisor
  self % divisor > 0 ? ( self / divisor ) + 1 : self / divisor
end

#characters(character, fail_on_negative: false) ⇒ Object



73
74
75
76
77
78
79
80
81
# File 'lib/vv/integer_methods.rb', line 73

def characters character, fail_on_negative: false
  message = "Expected single character, not #{character}."
  fail ArgumentError, message if character.length > 1

  message = "Expected non-negative integer, not `#{self}`."
  fail message if self < 0 and fail_on_negative

  ( self > 0 ) ? ( character * self ) : String.empty_string
end

#dashesObject



69
70
71
# File 'lib/vv/integer_methods.rb', line 69

def dashes
  characters String.dash
end

#exbibytesObject Also known as: exbibyte, EiB



59
60
61
# File 'lib/vv/integer_methods.rb', line 59

def exbibytes
  self.pebibytes * 1024
end

#gibibytesObject Also known as: gibibyte, GiB



41
42
43
# File 'lib/vv/integer_methods.rb', line 41

def gibibytes
  self.mebibytes * 1024
end

#kibibytesObject Also known as: kibibyte, KiB



29
30
31
# File 'lib/vv/integer_methods.rb', line 29

def kibibytes
  self * 1024
end

#mebibytesObject Also known as: mebibyte, MiB



35
36
37
# File 'lib/vv/integer_methods.rb', line 35

def mebibytes
  self.kibibytes * 1024
end

#pebibytesObject Also known as: pebibyte, PiB



53
54
55
# File 'lib/vv/integer_methods.rb', line 53

def pebibytes
  self.tebibytes * 1024
end

#spacesObject



65
66
67
# File 'lib/vv/integer_methods.rb', line 65

def spaces
  characters String.space
end

#tebibytesObject Also known as: tebibyte, TiB



47
48
49
# File 'lib/vv/integer_methods.rb', line 47

def tebibytes
  self.gibibytes * 1024
end

#to_i!Object



83
84
85
# File 'lib/vv/integer_methods.rb', line 83

def to_i!
  self
end

#vv_jsonObject



16
17
18
# File 'lib/vv/integer_methods.rb', line 16

def vv_json
  self.to_json
end