Class: File
Instance Method Summary collapse
- #content_line_separator ⇒ Object private
-
#default_line_separator ⇒ Object
private
Returns the default line separator.
- #discover_line_separator ⇒ Object private
- #infer_line_separator ⇒ Object private
- #type_line_separator ⇒ Object private
Instance Method Details
#content_line_separator ⇒ Object (private)
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/jinx/helpers/file_separator.rb', line 41 def content_line_separator begin saved_pos = pos # remember where we were # read a chunk until a separator is discovered sep = discover_line_separator # tricky seek() clone to work around GzipReader's lack of seek() rewind # reset back to the remembered position chunks, residual = saved_pos.divmod(1024) chunks.times { read(1024) } read(residual) rescue IOError # stream not opened for reading end sep end |
#default_line_separator ⇒ Object (private)
Returns the default line separator. The logic is borrowed from the FasterCVS gem.
26 27 28 |
# File 'lib/jinx/helpers/file_separator.rb', line 26 def default_line_separator @def_line_sep ||= infer_line_separator end |
#discover_line_separator ⇒ Object (private)
57 58 59 60 61 62 63 64 |
# File 'lib/jinx/helpers/file_separator.rb', line 57 def discover_line_separator # read a chunk until a separator is discovered while (sample = read(1024)) do sample += read(1) if sample[-1, 1] == "\r" and not eof? # try to find a standard separator return $& if sample =~ /\r\n?|\n/ end end |
#infer_line_separator ⇒ Object (private)
30 31 32 |
# File 'lib/jinx/helpers/file_separator.rb', line 30 def infer_line_separator type_line_separator or content_line_separator or $/ end |
#type_line_separator ⇒ Object (private)
34 35 36 37 38 39 |
# File 'lib/jinx/helpers/file_separator.rb', line 34 def type_line_separator if [ARGF, STDIN, STDOUT, STDERR].include?(self) or (defined?(Zlib) and self.class == Zlib::GzipWriter) then return $/ end end |