Skip to content

Instantly share code, notes, and snippets.

@matthewford
Created April 20, 2012 11:28
Show Gist options
  • Save matthewford/2427909 to your computer and use it in GitHub Desktop.
Save matthewford/2427909 to your computer and use it in GitHub Desktop.
utf8
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