class LookupError

lookup.rb – simple keyword lookup routine

Copyright 2013-2017, Alan K. Stebbens <aks@stebbens.org>

require 'lookup'

lookup - lookup a keyword in a list, in a case-insensitive, disambiguous way

:call-seq:

result = lookup list, key, err_notfound="%s not found", err_ambig="% is ambiguous"
result = list.lookup( key, err_notfound, err_ambig )
result = list.lookup( key, err_notfound )
result = list.lookup( key )

Lookup key in list, which can be an array or a hash. Return the one that matches exactly, or matches using case-insensitive, unambiguous matches, or raise a LookupError with a message.

LookupError is a subclass of StandardError.

LookupNotFoundError, a subclass of LookupError, is raised when a keyword is not found, and only if `err_notfound` is not nil.

LookupAmbigError, a subsclass of LookupError, is raised when a keyword search matches multiple entries from the list, and only if `err_ambig` is not nil.

If err_notfound is nil, do not raise a LookupNotFoundError error, and return nil.

If err_ambigmsg is nil, do not raise a LookupAmbigError, and return the list of possible results.