Method: String#titleize

Defined in:
lib/bcl/core_ext.rb

#titleizeObject

simple method to create titles – very custom to catch known inflections



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/bcl/core_ext.rb', line 27

def titleize
  arr = ['a', 'an', 'the', 'by', 'to']
  upcase_arr = ['DX', 'EDA', 'AEDG', 'LPD', 'COP']
  r = tr('_', ' ').gsub(/\w+/) do |match|
    match_result = match
    if upcase_arr.include?(match.upcase)
      match_result = upcase_arr[upcase_arr.index(match.upcase)]
    elsif arr.include?(match)
      match_result = match
    else
      match_result = match.capitalize
    end
    match_result
  end

  r
end