Created
July 11, 2013 06:00
-
-
Save radar/5972885 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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