# This pattern matches strings of capitals starting with a "vowel-sound"
# consonant followed by another consonant, and which are not likely
# to be real words (oh, all right then, it's just magic!)
A_abbrev = %{
(?! FJO | [HLMNS]Y. | RY[EO] | SQU
| ( F[LR]? | [HL] | MN? | N | RH? | S[CHKLMNPTVW]? | X(YL)?) [AEIOU])
[FHLMNRSX][A-Z]
}
# This pattern codes the beginnings of all english words begining with a
# 'y' followed by a consonant. Any other y-consonant prefix therefore
# implies an abbreviation.
A_y_cons = 'y(b[lor]|cl[ea]|fere|gg|p[ios]|rou|tt)'
# Exceptions to exceptions
A_explicit_an = matchgroup( "euler", "hour(?!i)", "heir", "honest", "hono" )
case word
# Handle special cases
when /^(#{A_explicit_an})/i
return "an #{word}"
# Handle abbreviations
when /^(#{A_abbrev})/x
return "an #{word}"
when /^[aefhilmnorsx][.-]/i
return "an #{word}"
when /^[a-z][.-]/i
return "a #{word}"
# Handle consonants
when /^[^aeiouy]/i
return "a #{word}"
# Handle special vowel-forms
when /^e[uw]/i
return "a #{word}"
when /^onc?e\b/i
return "a #{word}"
when /^uni([^nmd]|mo)/i
return "a #{word}"
when /^u[bcfhjkqrst][aeiou]/i
return "a #{word}"
# Handle vowels
when /^[aeiou]/i
return "an #{word}"
# Handle y… (before certain consonants implies (unnaturalized) "i.." sound)
when /^(#{A_y_cons})/i
return "an #{word}"
# Otherwise, guess "a"
else
return "a #{word}"
end
94 ### Wrap one or more parts in a non-capturing alteration Regexp
95 def self::matchgroup( *parts )
96 re = parts.flatten.join("|")
97 "(?:#{re})"
98 end