Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/collins_shell/monkeypatch.rb

Instance Method Summary collapse

Instance Method Details

#is_disk_size?Boolean

Returns:

  • (Boolean)


35
36
37
38
# 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_bytesObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# 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