class String

Public Instance Methods

encrypt() click to toggle source

Encrypts a password

return

The encrypted string

# File lib/utility/utility.rb, line 44
def encrypt
  alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./'
  salt = "#{alphabet[rand(64)].chr}#{alphabet[rand(64)].chr}"
  self.crypt(salt)
end
is_match?(str) click to toggle source

Takes a string containing a list of keywords, like ‘hello world’, and checks if ‘str’ is a prefix of any of those words? “hell” would be true

# File lib/utility/utility.rb, line 26
def is_match? str
  return false if self.empty? || str.nil? || str.empty?
  lst = self.split(' ')
  lst.each do |s|
    return true if str.downcase == s.slice(0...str.size).downcase
  end
  false
end
is_passwd?(pwd) click to toggle source

Compares the password with the string

pwd

The encrypted password

return

true if they are equal, false if not

# File lib/utility/utility.rb, line 38
def is_passwd?(pwd)
  pwd == self.crypt(pwd)
end
is_prefix?(str) click to toggle source

Checks if ‘str’ is a prefix of this string

# File lib/utility/utility.rb, line 18
def is_prefix? str
  return false if self.empty? || str.nil? || str.empty?
  self.downcase == str.slice(0...self.size).downcase
end
proper_name() click to toggle source

Make string into proper name removes digits, downcases and then capitalizes words. Sorry it doesn’t like McManus but likes O’Mally

# File lib/utility/utility.rb, line 53
def proper_name
  str = self.dup
  str.gsub!(%r\d+/,'')
  str.gsub!(%r\w+/) {|m|  m.downcase!; m[0] = m[0].chr.upcase; m}
  str
end