Created
September 8, 2013 13:38
-
-
Save abstraktor/6484769 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
#!/usr/bin/env ruby | |
#:set ts=2 | |
class EndedConverter | |
def endings | |
[ "\n\r", "\n", "\r" ] | |
end | |
def initialize(filename) | |
@str = File.read(filename) | |
encode(@str) | |
File.open(filename, "w") {|file| file.write(@str) } | |
end | |
def encode(str) | |
# See String#encode | |
encoding_options = { | |
:invalid => :replace, # Replace invalid byte sequences | |
:undef => :replace, # Replace anything not defined in ASCII | |
:replace => '', # Use a blank for those replacements | |
:universal_newline => true # Always break lines with \n | |
} | |
str.encode! Encoding.find('ASCII'), encoding_options | |
end | |
end | |
if __FILE__ == $0 then | |
abort "usage: #{$0} filename1, filename2" if ARGV.size < 1 | |
ARGV[0].split(",").each do |filename| | |
puts "converting #{filename}" | |
EndedConverter.new(filename) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment