Skip to content

Instantly share code, notes, and snippets.

@abstraktor
Created September 8, 2013 13:38
Show Gist options
  • Save abstraktor/6484769 to your computer and use it in GitHub Desktop.
Save abstraktor/6484769 to your computer and use it in GitHub Desktop.
#!/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