Last active
August 26, 2016 20:37
-
-
Save sokratis12GR/14a07a302929f8116ed2daa7403316ff to your computer and use it in GitHub Desktop.
This file contains 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
class String | |
def underscore | |
self.gsub(/::/, '/'). | |
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). | |
gsub(/([a-z\d])([A-Z])/,'\1_\2'). | |
tr("-", "_"). | |
downcase | |
end | |
end | |
Dir.glob("*.{json,png}").each do |entry| | |
# Renaming the files while adding `_` between the words and making them lowercase | |
next if entry == '.' || entry == '..' | |
new_entry = entry.underscore | |
File.rename(entry, new_entry) | |
puts "Renamed #{entry} to #{new_entry}." | |
old_text = File.basename("*.json", ".json") | |
new_text = File.basename("*.json", ".json") | |
text = File.read(file_name) | |
new_contents = text.gsub(old_text, new_text) | |
# To merely print the contents of the file, use: | |
puts new_contents | |
# To write changes to the file, use: | |
File.open(file_name, "w") {|file| file.puts new_contents } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment