Module: IndefiniteArticle
- Defined in:
- lib/indefinite_article.rb,
lib/indefinite_article/version.rb
Constant Summary collapse
- A_REQUIRING_PATTERNS =
/^(([bcdgjkpqtuvwyz]|onc?e|onearmed|onetime|ouija)$|e[uw]|uk|ubi|ubo|oaxaca|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)
/^(NDA)$/
- VERSION =
"0.2.5"
Instance Method Summary collapse
- #indefinite_article ⇒ Object
- #with_indefinite_article(upcase = false) ⇒ Object (also: #indefinitize)
Instance Method Details
#indefinite_article ⇒ Object
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 |