Class String
In: lib/utility/utility.rb
Parent: Object
String
Utility
dot/f_59.png

Methods

Public Instance methods

Encrypts a password

return
The encrypted string

[Source]

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

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

[Source]

# 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

Compares the password with the string

pwd
The encrypted password
return
true if they are equal, false if not

[Source]

# File lib/utility/utility.rb, line 38
  def is_passwd?(pwd)
    pwd == self.crypt(pwd)
  end

Checks if ‘str’ is a prefix of this string

[Source]

# 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

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

[Source]

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

[Validate]