Class: File
Instance Method Summary
collapse
#compact, #compact_map, #detect_value, #detect_with_value, #difference, #empty?, #filter, #first, #flatten, #hashify, #intersect, #join, #last, #partial_sort, #partial_sort!, #partial_sort_by, #size, #to_compact_hash, #to_compact_hash_with_index, #to_series, #transform, #union
Instance Method Details
#content_line_separator ⇒ Object
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 sep = discover_line_separator
rewind
chunks, residual = saved_pos.divmod(1024)
chunks.times { read(1024) }
read(residual)
rescue IOError end
sep
end
|
#default_line_separator ⇒ Object
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
57
58
59
60
61
62
63
64
|
# File 'lib/jinx/helpers/file_separator.rb', line 57
def discover_line_separator
while (sample = read(1024)) do
sample += read(1) if sample[-1, 1] == "\r" and not eof?
return $& if sample =~ /\r\n?|\n/
end
end
|
#infer_line_separator ⇒ Object
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
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
|