Class: String
Instance Method Summary collapse
-
#alnum? ⇒ Boolean
Self test alphanum String class.
-
#alpha? ⇒ Boolean
Self test alpha String class.
-
#decrypt(key) ⇒ Object
Decrypt a string using a key.
-
#encrypt(key) ⇒ Object
Encrypt a string using a key.
-
#fix(size, pattern = ' ') ⇒ Object
Justity relative left or right position filled with a espefific char in String.
-
#nil? ⇒ Boolean
Self test nil String class.
Instance Method Details
#alnum? ⇒ Boolean
Self test alphanum String class.
232 233 234 |
# File 'lib/lib/utils.rb', line 232 def alnum? !!match(/^[[:alnum:]]+$/) end |
#alpha? ⇒ Boolean
Self test alpha String class.
239 240 241 |
# File 'lib/lib/utils.rb', line 239 def alpha? !!match(/^[[:alpha:]]+$/) end |
#decrypt(key) ⇒ Object
Decrypt a string using a key. sample msg = "teste do encrypt".light_blue passwd = 'tools999' encrypted = msg.encrypt passwd puts (encrypted.decrypt passwd)
225 226 227 |
# File 'lib/lib/utils.rb', line 225 def decrypt(key) Encrypt.load self, key end |
#encrypt(key) ⇒ Object
Encrypt a string using a key. sample msg = "teste do encrypt".light_blue passwd = 'tools999' encrypted = msg.encrypt passwd puts (encrypted.decrypt passwd)
214 215 216 |
# File 'lib/lib/utils.rb', line 214 def encrypt(key) Encrypt.dump self, key end |
#fix(size, pattern = ' ') ⇒ Object
Justity relative left or right position filled with a espefific char in String.
sample:
"TESTE".fix(10,'xy') # => xxxxxTESTE "TESTE".fix(-10,'xy') # => TESTExxxxx
198 199 200 201 202 203 204 205 |
# File 'lib/lib/utils.rb', line 198 def fix(size, pattern=' ') if size >= 0 self[0...size].rjust(size, pattern) else diff = size.abs - self.size self + ''.fix(diff,pattern) end end |
#nil? ⇒ Boolean
Self test nil String class.
183 184 185 |
# File 'lib/lib/utils.rb', line 183 def nil? return '' if self == nil end |