Created
December 3, 2009 21:21
-
-
Save seven1m/248536 to your computer and use it in GitHub Desktop.
dirty little script I used to fix escaped character sequences in a yaml file
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
lines = File.read(ARGV.first).split("\n") | |
File.open(ARGV.last, 'w') do |out| | |
lines.each do |line| | |
if line =~ /:/ | |
key, value = line.split(/:\s*/, 2) | |
value = eval(value) if value =~ /^"/ | |
if value =~ /\{|"|:/ | |
value.gsub!(/"/, "\\\"") | |
value = "\"#{value}\"" | |
end | |
out.write("#{key}: #{value}\n") | |
else | |
out.write("#{line}\n") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment