Class: String

Inherits:
Object show all
Defined in:
lib/lib/utils.rb

Instance Method Summary collapse

Instance Method Details

#alnum? ⇒ Boolean

Self test alphanum String class.

Returns:

  • (Boolean) —

    boolean



256
257
258
# File 'lib/lib/utils.rb', line 256

def alnum?
  !!match(/^[[:alnum:]]+$/)
end

#alpha? ⇒ Boolean

Self test alpha String class.

Returns:

  • (Boolean) —

    boolean



263
264
265
# File 'lib/lib/utils.rb', line 263

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)

Returns:

  • decrypt string



249
250
251
# File 'lib/lib/utils.rb', line 249

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)

Returns:

  • encrypt string



238
239
240
# File 'lib/lib/utils.rb', line 238

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

Parameters:

  • size —

    to justify.

  • pattern (defaults to: ' ') —

    pattern do justify

Returns:

  • formated string



222
223
224
225
226
227
228
229
# File 'lib/lib/utils.rb', line 222

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.

Returns:

  • (Boolean) —

    boolean



207
208
209
# File 'lib/lib/utils.rb', line 207

def nil?
  return '' if self == nil
end