Class: String

Inherits:
Object show all
Defined in:
lib/summary_judgement/core_extensions.rb

Constant Summary collapse

WORDS_WITH_INITIAL_VOWELS_THAT_ACT_LIKE_WORDS_WITH_INITIAL_CONSONANTS =
%w(one united)
INDEFINITE_ARTICLES =
{ :vowel => 'an', :consonant => 'a'}
VOWELS =
%w(a e i o u)

Instance Method Summary collapse

Instance Method Details

#first_termObject



24
25
26
# File 'lib/summary_judgement/core_extensions.rb', line 24

def first_term
  split('-').first
end

#first_wordObject



20
21
22
# File 'lib/summary_judgement/core_extensions.rb', line 20

def first_word
  split(' ').first
end

#indefinite_articleObject



2
3
4
5
6
7
8
9
10
# File 'lib/summary_judgement/core_extensions.rb', line 2

def indefinite_article
  if WORDS_WITH_INITIAL_VOWELS_THAT_ACT_LIKE_WORDS_WITH_INITIAL_CONSONANTS.include? first_word.first_term.downcase
    INDEFINITE_ARTICLES[:consonant]
  elsif VOWELS.include? first.downcase
    INDEFINITE_ARTICLES[:vowel]
  else
    INDEFINITE_ARTICLES[:consonant]
  end
end

#pluralize_on(qty) ⇒ Object



16
17
18
# File 'lib/summary_judgement/core_extensions.rb', line 16

def pluralize_on(qty)
  qty.is_a?(Numeric) and qty > 1 ? pluralize : self
end

#with_indefinite_article(upcase = false) ⇒ Object



12
13
14
# File 'lib/summary_judgement/core_extensions.rb', line 12

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