Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-xen.rb,
lib/ruby-xen.rb

Instance Method Summary collapse

Instance Method Details

#to_megabytesObject

Convert string to megabytes



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/ruby-xen.rb', line 65

def to_megabytes
  gigabytes = /(gb|gig|gigabytes?)/i
  megabytes = /(mb|meg|megabytes?)/i
  kilobytes = /(kb|kilobytes?)/i
  bytes = /bytes?/i
  
  if index(gigabytes)
    return sub(gigabytes,'').to_i * 1024
  elsif index(megabytes)
    return sub(megabytes,'').to_i
  elsif index(kilobytes)
    return sub(kilobytes,'').to_i / 1024
  elsif index(bytes)
    return sub(bytes,'').to_i / (1024*1024)
  else
    return self.to_i
  end
end

#underscorizeObject



107
108
109
# File 'lib/ruby-xen.rb', line 107

def underscorize
  self.sub("-", "__")
end

#ununderscorizeObject



110
111
112
# File 'lib/ruby-xen.rb', line 110

def ununderscorize
  self.sub("__", "-")
end