lib/edl/linebreak_magician.rb in edl-0.1.4 vs lib/edl/linebreak_magician.rb in edl-0.1.5
- old
+ new
@@ -1,24 +1,11 @@
-require "delegate"
-
# EDLs sometimes come with \r line breaks, and this is something that fails
# with Ruby standard line separator detection. We need something to help us
-# with that
-class EDL::LinebreakMagician < DelegateClass(IO)
-
- def initialize(with_file)
- sample = with_file.read(2048)
- @linebreak = ["\r\n", "\r", "\n"].find{|separator| sample.include?(separator) }
- with_file.rewind
- __setobj__(with_file)
+# with that. In this case we can just do a bulk replace because EDLs will be relatively
+# small for even very long features.
+class EDL::LinebreakMagician < StringIO
+ LOOSE_CR = /#{Regexp.escape("\r")}/
+ def initialize(with_io)
+ blob = with_io.read
+ super(blob.gsub(LOOSE_CR, "\n"))
end
-
- def each(sep_string = $/, &blk)
- super(@linebreak || sep_string, &blk)
- end
- alias_method :each_line, :each
-
- def gets(sep_string = $/)
- super(@linebreak || sep_string)
- end
-
end
\ No newline at end of file