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.
- #help? ⇒ Boolean
-
#num? ⇒ Boolean
Self test digits String class.
-
#numeric? ⇒ Boolean
Self test numeric String class.
Instance Method Details
#alnum? ⇒ Boolean
Self test alphanum String class.
62 63 64 |
# File 'lib/lib/string.rb', line 62 def alnum? !match(/^[[:alnum:]]+$/).nil? end |
#alpha? ⇒ Boolean
Self test alpha String class.
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)
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)
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
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
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.
55 56 57 |
# File 'lib/lib/string.rb', line 55 def num? !match(/^[[:digit:]]+$/).nil? end |
#numeric? ⇒ Boolean
Self test numeric String class.
46 47 48 49 50 |
# File 'lib/lib/string.rb', line 46 def numeric? !Float(self).nil? rescue StandardError false end |