Parent

Files

String

Constants

ROMAN

Taken from O'Reilly's Perl Cookbook 6.23. Regular Expression Grabbag.

ROMAN_VALUES

Public Instance Methods

_crypt(salt=nil) click to toggle source
Alias for: crypt
acronymize() click to toggle source

CREDIT: Robert Fey

# File lib/facets/core-uncommon/facets/string/acronym.rb, line 4
def acronymize
        gsub(/(([a-zA-Z0-9])([a-zA-Z0-9])*)./,"\\2")
end
crypt(salt=nil) click to toggle source

Common Unix cryptography method. This adds a default salt to the built-in crypt method.

NOTE: This is not (presently) a common core extension and is not loaded automatically when using require 'facets'.

# File lib/facets/core-uncommon/facets/string/crypt.rb, line 11
def crypt(salt=nil)
  salt ||= (
    (rand(26) + (rand(2) == 0 ? 65 : 97) ).chr +
    (rand(26) + (rand(2) == 0 ? 65 : 97) ).chr
  )
  _crypt(salt)
end
Also aliased as: _crypt
roman() click to toggle source

Considers string a Roman numeral numeral, and converts it to the corresponding integer.

NOTE: This is not (presently) a common core extension and is not loaded automatically when using require 'facets'.

# File lib/facets/core-uncommon/facets/integer/roman.rb, line 54
def roman
  roman = upcase
  raise unless roman?
  last = roman[-1,1]
  roman.reverse.split('').inject(0) do |result, c|
    if ROMAN_VALUES[c] < ROMAN_VALUES[last]
      result -= ROMAN_VALUES[c]
    else
      last = c
      result += ROMAN_VALUES[c]
    end
  end
end
roman?() click to toggle source

Returns true iif the subject is a valid Roman numeral.

NOTE: This is not (presently) a common core extension and is not loaded automatically when using require 'facets'.

# File lib/facets/core-uncommon/facets/integer/roman.rb, line 72
def roman?
  ROMAN =~ upcase
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.