Created
March 10, 2011 19:44
-
-
Save cfcosta/864774 to your computer and use it in GitHub Desktop.
Pequeno script para consertar a capitalização de nomes de cidades, por exemplo.
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
require 'unicode' | |
class String | |
def downcase | |
Unicode.downcase self | |
end | |
def capitalize | |
Unicode.capitalize self | |
end | |
def capitalize! | |
replace(capitalize) | |
end | |
def correct_capitalization | |
blacklist = %w{a e o da de do com as os das dos} | |
words = self.split(' ').map(&:downcase) | |
words.each { |word| word.capitalize! unless blacklist.include? word } | |
words.join ' ' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment