Module: IndefiniteArticle

Included in:
String, Symbol
Defined in:
lib/indefinite_article.rb,
lib/indefinite_article/version.rb

Constant Summary collapse

A_REQUIRING_PATTERNS =
/^(([bcdgjkpqtuvwyz]|onc?e|onearmed|onetime|ouija|oaxaca|oaxacan|oaxacania|oaxacanthaxia)$|e[uw]|uk|ubi|ubo|ufo|ur[aeiou]|use|ut([^t])|unani|uni(l[^l]|[a-ko-z]))/i
AN_REQUIRING_PATTERNS =
/^([aefhilmnorsx]$|hono|honest|hour|heir|[aeiou]|8|11)/i
UPCASE_A_REQUIRING_PATTERNS =
/^(UN$)/
UPCASE_AN_REQUIRING_PATTERNS =

need if we decide to support acronyms like “XL” (extra-large)

/^$/
VERSION =
"0.2.4"

Instance Method Summary collapse

Instance Method Details

#indefinite_articleObject



11
12
13
14
15
16
17
18
19
# File 'lib/indefinite_article.rb', line 11

def indefinite_article
  first_word = to_s.split(/[- ]/).first
  if (first_word[AN_REQUIRING_PATTERNS] || first_word[UPCASE_AN_REQUIRING_PATTERNS]) &&
     !(first_word[A_REQUIRING_PATTERNS] || first_word[UPCASE_A_REQUIRING_PATTERNS])
    'an'
  else
    'a'
  end unless first_word.nil?
end

#with_indefinite_article(upcase = false) ⇒ Object Also known as: indefinitize



21
22
23
# File 'lib/indefinite_article.rb', line 21

def with_indefinite_article(upcase = false)
  "#{upcase ? indefinite_article.humanize : indefinite_article}#{ ' ' unless self.blank? }#{self}"
end