Skip to content

Instantly share code, notes, and snippets.

@radar
Created July 11, 2013 06:00
Show Gist options
  • Save radar/5972885 to your computer and use it in GitHub Desktop.
Save radar/5972885 to your computer and use it in GitHub Desktop.
def smart_titleize(word, pattern)
words = word.split(' ')
processed_words = []
words.each do |aWord|
aWord = Regexp.escape(aWord)
aWord = aWord.capitalize unless Regexp.escape("#{pattern}").match(aWord) || /^[A-Z]*$/.match(aWord) || /^[a-z]{2,}$/.match(aWord) || /^[0-9]*$/.match(aWord)
aWord = aWord.gsub(/-([A-Za-z0-9]+)/) {|s| s.upcase}
aWord = aWord.gsub(/(AR\-15)/i) {$&.upcase}
aWord = aWord.gsub(/(TAC-)/i) {$&.upcase}
processed_words << aWord
end
processed_words.jo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment