Sha256: 3e37b69114ccf33d1028bb0807b7323d42717bca9353ccf9dcf3b6e4631faf09

Contents?: true

Size: 1017 Bytes

Versions: 10

Compression:

Stored size: 1017 Bytes

Contents

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

  def with_indefinite_article(upcase = false)
    "#{upcase ? indefinite_article.humanize : indefinite_article}#{ ' ' unless self.blank? }#{self}"
  end
  
  def pluralize_on(qty)
    qty.is_a?(Numeric) and qty > 1 ? pluralize : self
  end
  
  def first_word
    split(' ').first
  end
  
  def first_term
    split('-').first
  end
  
  WORDS_WITH_INITIAL_VOWELS_THAT_ACT_LIKE_WORDS_WITH_INITIAL_CONSONANTS = %w(one)
  INDEFINITE_ARTICLES = { :vowel => 'an', :consonant => 'a'}
  VOWELS = %w(a e i o u)
end

class Object
  def recursive_send(*methods)
    return self if methods.empty?
    m = methods.shift
    send(m).recursive_send(*methods)
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
summary_judgement-1.3.4 lib/summary_judgement/core_extensions.rb
summary_judgement-1.3.3 lib/summary_judgement/core_extensions.rb
summary_judgement-1.3.2 lib/summary_judgement/core_extensions.rb
summary_judgement-1.3.1 lib/summary_judgement/core_extensions.rb
summary_judgement-1.3.0 lib/summary_judgement/core_extensions.rb
summary_judgement-1.2.4 lib/summary_judgement/core_extensions.rb
summary_judgement-1.2.3 lib/summary_judgement/core_extensions.rb
summary_judgement-1.2.2 lib/summary_judgement/core_extensions.rb
summary_judgement-1.2.1 lib/summary_judgement/core_extensions.rb
summary_judgement-1.2.0 lib/summary_judgement/core_extensions.rb