class String

Public Instance Methods

is_disk_size?() click to toggle source
# File lib/collins_shell/monkeypatch.rb, line 35
def is_disk_size?
  s = self.downcase
  s.include?("gb") or s.include?("mb") or s.include?("tb")
end
to_bytes() click to toggle source
# File lib/collins_shell/monkeypatch.rb, line 40
def to_bytes
  s = self.downcase
  size_h = ""
  multiplier = 0
  if s.include?("mb") then
    multiplier = (1024 ** 2)
    size_h = s.split('mb')[0]
  elsif s.include?("gb") then
    multiplier = (1024 ** 3)
    size_h = s.split('gb')[0]
  elsif s.include?("tb") then
    multiplier = (1024 ** 4)
    size_h = s.split('tb')[0]
  else
    raise Exception.new("Unknown size: #{s}")
  end
  (multiplier * size_h.to_f).floor.to_i
end