csv 3.2.2 → 3.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/NEWS.md +324 -5
- data/README.md +2 -2
- data/doc/csv/options/generating/write_headers.rdoc +1 -1
- data/doc/csv/options/parsing/liberal_parsing.rdoc +21 -2
- data/doc/csv/recipes/filtering.rdoc +85 -17
- data/doc/csv/recipes/generating.rdoc +2 -2
- data/doc/csv/recipes/parsing.rdoc +14 -5
- data/lib/csv/core_ext/array.rb +1 -1
- data/lib/csv/core_ext/string.rb +1 -1
- data/lib/csv/fields_converter.rb +10 -2
- data/lib/csv/input_record_separator.rb +1 -14
- data/lib/csv/parser.rb +238 -108
- data/lib/csv/row.rb +1 -1
- data/lib/csv/table.rb +15 -6
- data/lib/csv/version.rb +1 -1
- data/lib/csv/writer.rb +4 -5
- data/lib/csv.rb +256 -44
- metadata +7 -67
- data/lib/csv/delete_suffix.rb +0 -18
- data/lib/csv/match_p.rb +0 -20
data/lib/csv/fields_converter.rb
CHANGED
|
@@ -4,6 +4,13 @@ class CSV
|
|
|
4
4
|
# Note: Don't use this class directly. This is an internal class.
|
|
5
5
|
class FieldsConverter
|
|
6
6
|
include Enumerable
|
|
7
|
+
|
|
8
|
+
NO_QUOTED_FIELDS = [] # :nodoc:
|
|
9
|
+
def NO_QUOTED_FIELDS.[](_index)
|
|
10
|
+
false
|
|
11
|
+
end
|
|
12
|
+
NO_QUOTED_FIELDS.freeze
|
|
13
|
+
|
|
7
14
|
#
|
|
8
15
|
# A CSV::FieldsConverter is a data structure for storing the
|
|
9
16
|
# fields converter properties to be passed as a parameter
|
|
@@ -44,7 +51,7 @@ class CSV
|
|
|
44
51
|
@converters.empty?
|
|
45
52
|
end
|
|
46
53
|
|
|
47
|
-
def convert(fields, headers, lineno)
|
|
54
|
+
def convert(fields, headers, lineno, quoted_fields=NO_QUOTED_FIELDS)
|
|
48
55
|
return fields unless need_convert?
|
|
49
56
|
|
|
50
57
|
fields.collect.with_index do |field, index|
|
|
@@ -63,7 +70,8 @@ class CSV
|
|
|
63
70
|
else
|
|
64
71
|
header = nil
|
|
65
72
|
end
|
|
66
|
-
|
|
73
|
+
quoted = quoted_fields[index]
|
|
74
|
+
field = converter[field, FieldInfo.new(index, lineno, header, quoted)]
|
|
67
75
|
end
|
|
68
76
|
break unless field.is_a?(String) # short-circuit pipeline for speed
|
|
69
77
|
end
|
|
@@ -4,20 +4,7 @@ require "stringio"
|
|
|
4
4
|
class CSV
|
|
5
5
|
module InputRecordSeparator
|
|
6
6
|
class << self
|
|
7
|
-
|
|
8
|
-
verbose, $VERBOSE = $VERBOSE, true
|
|
9
|
-
stderr, $stderr = $stderr, StringIO.new
|
|
10
|
-
input_record_separator = $INPUT_RECORD_SEPARATOR
|
|
11
|
-
begin
|
|
12
|
-
$INPUT_RECORD_SEPARATOR = "\r\n"
|
|
13
|
-
is_input_record_separator_deprecated = (not $stderr.string.empty?)
|
|
14
|
-
ensure
|
|
15
|
-
$INPUT_RECORD_SEPARATOR = input_record_separator
|
|
16
|
-
$stderr = stderr
|
|
17
|
-
$VERBOSE = verbose
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
if is_input_record_separator_deprecated
|
|
7
|
+
if RUBY_VERSION >= "3.0.0"
|
|
21
8
|
def value
|
|
22
9
|
"\n"
|
|
23
10
|
end
|