Class: String

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

Instance Method Summary collapse

Instance Method Details

#alnum?Boolean

Self test alphanum String class.

Returns:

  • (Boolean)

    boolean



62
63
64
# File 'lib/lib/string.rb', line 62

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

#alpha?Boolean

Self test alpha String class.

Returns:

  • (Boolean)

    boolean



69
70
71
# File 'lib/lib/string.rb', line 69

def alpha?
  !match(/^[[:alpha:]]+$/).nil?
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



39
40
41
# File 'lib/lib/string.rb', line 39

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



28
29
30
# File 'lib/lib/string.rb', line 28

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



12
13
14
15
16
17
18
19
# File 'lib/lib/string.rb', line 12

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)


73
74
75
76
77
78
79
80
81
82
# File 'lib/lib/string.rb', line 73

def help?
  if eql?('?') ||
     eql?('-h')     ||
     eql?('--help') ||
     eql?('help')
    true
  else
    false
  end
end

#num?Boolean

Self test digits String class.

Returns:

  • (Boolean)

    boolean



55
56
57
# File 'lib/lib/string.rb', line 55

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

#numeric?Boolean

Self test numeric String class.

Returns:

  • (Boolean)

    boolean



46
47
48
49
50
# File 'lib/lib/string.rb', line 46

def numeric?
  !Float(self).nil?
rescue StandardError
  false
end