summaryrefslogtreecommitdiff
path: root/lib/csv/input_record_separator.rb
blob: bbf13479f7883a8788746773fb30ca8158449988 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require "English"
require "stringio"

class CSV
  module InputRecordSeparator
    class << self
      is_input_record_separator_deprecated = false
      verbose, $VERBOSE = $VERBOSE, true
      stderr, $stderr = $stderr, StringIO.new
      input_record_separator = $INPUT_RECORD_SEPARATOR
      begin
        $INPUT_RECORD_SEPARATOR = "\r\n"
        is_input_record_separator_deprecated = (not $stderr.string.empty?)
      ensure
        $INPUT_RECORD_SEPARATOR = input_record_separator
        $stderr = stderr
        $VERBOSE = verbose
      end

      if is_input_record_separator_deprecated
        def value
          "\n"
        end
      else
        def value
          $INPUT_RECORD_SEPARATOR
        end
      end
    end
  end
end