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
- #bits ⇒ Object
- #ceil_divide(divisor) ⇒ Object
- #characters(character, fail_on_negative: false) ⇒ Object
- #dashes ⇒ Object
- #exbibytes ⇒ Object (also: #exbibyte, #EiB)
- #gibibytes ⇒ Object (also: #gibibyte, #GiB)
- #kibibytes ⇒ Object (also: #kibibyte, #KiB)
- #mebibytes ⇒ Object (also: #mebibyte, #MiB)
- #pebibytes ⇒ Object (also: #pebibyte, #PiB)
- #spaces ⇒ Object
- #tebibytes ⇒ Object (also: #tebibyte, #TiB)
- #to_i! ⇒ Object
- #vv_json ⇒ Object
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
#bits ⇒ Object
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 = "Expected single character, not #{character}." fail ArgumentError, if character.length > 1 = "Expected non-negative integer, not `#{self}`." fail if self < 0 and fail_on_negative ( self > 0 ) ? ( character * self ) : String.empty_string end |
#dashes ⇒ Object
69 70 71 |
# File 'lib/vv/integer_methods.rb', line 69 def dashes characters String.dash end |
#exbibytes ⇒ Object Also known as: exbibyte, EiB
59 60 61 |
# File 'lib/vv/integer_methods.rb', line 59 def exbibytes self.pebibytes * 1024 end |
#gibibytes ⇒ Object Also known as: gibibyte, GiB
41 42 43 |
# File 'lib/vv/integer_methods.rb', line 41 def gibibytes self.mebibytes * 1024 end |
#kibibytes ⇒ Object Also known as: kibibyte, KiB
29 30 31 |
# File 'lib/vv/integer_methods.rb', line 29 def kibibytes self * 1024 end |
#mebibytes ⇒ Object Also known as: mebibyte, MiB
35 36 37 |
# File 'lib/vv/integer_methods.rb', line 35 def mebibytes self.kibibytes * 1024 end |
#pebibytes ⇒ Object Also known as: pebibyte, PiB
53 54 55 |
# File 'lib/vv/integer_methods.rb', line 53 def pebibytes self.tebibytes * 1024 end |
#spaces ⇒ Object
65 66 67 |
# File 'lib/vv/integer_methods.rb', line 65 def spaces characters String.space end |
#tebibytes ⇒ Object 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_json ⇒ Object
16 17 18 |
# File 'lib/vv/integer_methods.rb', line 16 def vv_json self.to_json end |