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



342
343
344
# File 'lib/lib/utils.rb', line 342

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

#alpha? ⇒ Boolean

Self test alpha String class.

Returns:

  • (Boolean) —

    boolean



349
350
351
# File 'lib/lib/utils.rb', line 349

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



321
322
323
# File 'lib/lib/utils.rb', line 321

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



310
311
312
# File 'lib/lib/utils.rb', line 310

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



294
295
296
297
298
299
300
301
# File 'lib/lib/utils.rb', line 294

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

#help? ⇒ Boolean

Returns:

  • (Boolean)


353
354
355
356
357
358
359
360
361
362
# File 'lib/lib/utils.rb', line 353

def help?
  if self.eql? '?'      or
     self.eql? '-h'     or
     self.eql? '--help' or
     self.eql? 'help'
     return true
  else
    return false
  end
end

#nil? ⇒ Boolean

Self test nil String class.

Returns:

  • (Boolean) —

    boolean



279
280
281
# File 'lib/lib/utils.rb', line 279

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

#num? ⇒ Boolean

Self test digits String class.

Returns:

  • (Boolean) —

    boolean



335
336
337
# File 'lib/lib/utils.rb', line 335

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

#numeric? ⇒ Boolean

Self test numeric String class.

Returns:

  • (Boolean) —

    boolean



328
329
330
# File 'lib/lib/utils.rb', line 328

def numeric?
  Float(aux) != nil rescue false
end