Created
April 20, 2012 11:28
-
-
Save matthewford/2427909 to your computer and use it in GitHub Desktop.
utf8
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 self.make_utf8_clean | |
mappings = [ ['α', 'α'], | |
['ß', 'β'], | |
['β', 'β'], | |
['’', '’'], | |
['“', '“'], | |
['â€\u009D;', '”'], | |
['â€', '”'], | |
['ö', 'ö'], | |
['®', '®'] | |
] | |
# Get the list of String columns | |
columns = Array.new | |
self.columns.each do |column| | |
if column.type.to_s == 'string' || column.type.to_s == 'text' | |
columns << column | |
end | |
end | |
# Go through each object -> column against all mappings | |
self.all.each do |obj| | |
columns.each do |column| | |
mappings.each do |mapping| | |
value = obj.attributes[column.name] | |
if value =~ /#{mapping[0]}/ | |
s = value.gsub(/#{mapping[0]}/, "#{mapping[1]}") | |
obj.update_attribute(column.name.to_sym, s) | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment