11== Recipes
22
33=== Contents
4- - {Parsing}[#label-Parsing]
5- - {Parse from String Without Headers}[#label-Parse+from+String+Without+Headers]
6- - {Parse from String with Headers}[#label-Parse+from+String+with+Headers]
7- - {Parse from File Without Headers}[#label-Parse+from+File+Without+Headers]
8- - {Parse from File with Headers}[#label-Parse+from+File+with+Headers]
9- - {Parse from IO Stream Without Headers}[#label-Parse+from+IO+Stream+Without+Headers]
10- - {Parse from IO Stream with Headers}[#label-Parse+from+IO+Stream+with+Headers]
11- - {Generating}[#label-Generating]
12- - {Generate to String Without Headers}[#label-Generate+to+String+Without+Headers]
13- - {Generate to String with Headers}[#label-Generate+to+String+with+Headers]
14- - {Generate to File Without Headers}[#label-Generate+to+File+Without+Headers]
15- - {Generate to File with Headers}[#label-Generate+to+File+with+Headers]
16- - {Generate to IO Stream Without Headers}[#label-Generate+to+IO+Stream+Without+Headers]
17- - {Generate to IO Stream with Headers}[#label-Generate+to+IO+Stream+with+Headers]
18- - {Filtering}[#label-Filtering]
19- - {Filter String to String Without Headers}[#label-Filter+String+to+String+Without+Headers]
20- - {Filter String to String with Headers}[#label-Filter+String+to+String+with+Headers]
21- - {Filter String to IO Stream Without Headers}[#label-Filter+String+to+IO+Stream+Without+Headers]
22- - {Filter String to IO Stream with Headers}[#label-Filter+String+to+IO+Stream+with+Headers]
23- - {Filter IO Stream to String Without Headers}[#label-Filter+IO+Stream+to+String+Without+Headers]
24- - {Filter IO Stream to String with Headers}[#label-Filter+IO+Stream+to+String+with+Headers]
25- - {Filter IO Stream to IO Stream Without Headers}[#label-Filter+IO+Stream+to+IO+Stream+Without+Headers]
26- - {Filter IO Stream to IO Stream with Headers}[#label-Filter+IO+Stream+to+IO+Stream+with+Headers]
27-
28- === Parsing
29-
30- ==== Parse from \String Without Headers
4+
5+ - {Parsing: Source Formats}[#label-Parsing-3A+Source+Formats]
6+ - {Parse from String}[#label-Parse+from+String]
7+ - {Parse from String Without Headers}[#label-Parse+from+String+Without+Headers]
8+ - {Parse from String with Headers}[#label-Parse+from+String+with+Headers]
9+ - {Parse from File}[#label-Parse+from+File]
10+ - {Parse from File Without Headers}[#label-Parse+from+File+Without+Headers]
11+ - {Parse from File with Headers}[#label-Parse+from+File+with+Headers]
12+ - {Parse from IO Stream}[#label-Parse+from+IO+Stream]
13+ - {Parse from IO Stream Without Headers}[#label-Parse+from+IO+Stream+Without+Headers]
14+ - {Parse from IO Stream with Headers}[#label-Parse+from+IO+Stream+with+Headers]
15+ - {Generating: Output Formats}[#label-Generating-3A+Output+Formats]
16+ - {Generate to String}[#label-Generate+to+String]
17+ - {Generate to String Without Headers}[#label-Generate+to+String+Without+Headers]
18+ - {Generate to String with Headers}[#label-Generate+to+String+with+Headers]
19+ - {Generate to File}[#label-Generate+to+File]
20+ - {Generate to File Without Headers}[#label-Generate+to+File+Without+Headers]
21+ - {Generate to File with Headers}[#label-Generate+to+File+with+Headers]
22+ - {Generate to IO Stream}[#label-Generate+to+IO+Stream]
23+ - {Generate to IO Stream Without Headers}[#label-Generate+to+IO+Stream+Without+Headers]
24+ - {Generate to IO Stream with Headers}[#label-Generate+to+IO+Stream+with+Headers]
25+ - {Filtering: Source and Output Formats}[#label-Filtering-3A+Source+and+Output+Formats]
26+ - {Filter String to String}[#label-Filter+String+to+String]
27+ - {Filter String to String Without Headers}[#label-Filter+String+to+String+Without+Headers]
28+ - {Filter String to String with Headers}[#label-Filter+String+to+String+with+Headers]
29+ - {Filter String to IO Stream}[#label-Filter+String+to+IO+Stream]
30+ - {Filter String to IO Stream Without Headers}[#label-Filter+String+to+IO+Stream+Without+Headers]
31+ - {Filter String to IO Stream with Headers}[#label-Filter+String+to+IO+Stream+with+Headers]
32+ - {Filter IO Stream to String}[#label-Filter+IO+Stream+to+String]
33+ - {Filter IO Stream to String Without Headers}[#label-Filter+IO+Stream+to+String+Without+Headers]
34+ - {Filter IO Stream to String with Headers}[#label-Filter+IO+Stream+to+String+with+Headers]
35+ - {Filter IO Stream to IO Stream}[#label-Filter+IO+Stream+to+IO+Stream]
36+ - {Filter IO Stream to IO Stream Without Headers}[#label-Filter+IO+Stream+to+IO+Stream+Without+Headers]
37+ - {Filter IO Stream to IO Stream with Headers}[#label-Filter+IO+Stream+to+IO+Stream+with+Headers]
38+
39+ === Parsing: Source Formats
40+
41+ ==== Parse from \String
42+
43+ ===== Parse from \String Without Headers
3144
3245\Class method CSV.parse can read a source \String all at once,
3346and so may have memory resource implications:
@@ -43,7 +56,7 @@ Output:
4356 ["bar", "1"]
4457 ["baz", "2"]
4558
46- ==== Parse from \String with Headers
59+ ===== Parse from \String with Headers
4760
4861\Class method CSV.parse can read a source \String all at once,
4962and so may have memory resource implications:
5972 #<CSV::Row "Name":"bar" "Value":"1">
6073 #<CSV::Row "Name":"baz" "Value":"2">
6174
62- ==== Parse from \File Without Headers
75+ ==== Parse from \File
76+
77+ ===== Parse from \File Without Headers
6378
6479\Class method CSV.read can read a file all at once:
6580 string = "foo,0\nbar,1\nbaz,2\n"
@@ -76,7 +91,7 @@ Output:
7691 ["bar", "1"]
7792 ["baz", "2"]
7893
79- ==== Parse from \File with Headers
94+ ===== Parse from \File with Headers
8095
8196Instance method CSV#read can reada file all at once:
8297 string = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
@@ -93,7 +108,9 @@ Output:
93108 #<CSV::Row "Name":"bar" "Value":"1">
94109 #<CSV::Row "Name":"baz" "Value":"2">
95110
96- ==== Parse from \IO Stream Without Headers
111+ ==== Parse from \IO Stream
112+
113+ ===== Parse from \IO Stream Without Headers
97114
98115\Class method CSV.parse can read an \IO stream all at once:
99116 string = "foo,0\nbar,1\nbaz,2\n"
@@ -114,7 +131,7 @@ Output:
114131 ["bar", "1"]
115132 ["baz", "2"]
116133
117- ==== Parse from \IO Stream with Headers
134+ ===== Parse from \IO Stream with Headers
118135
119136\Class method CSV.parse can read an \IO stream all at once:
120137 string = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
@@ -135,7 +152,7 @@ Output:
135152 #<CSV::Row "Name":"bar" "Value":"1">
136153 #<CSV::Row "Name":"baz" "Value":"2">
137154
138- === Generating
155+ === Generating: Output Formats
139156
140157==== Generate to \String Without Headers
141158
@@ -150,7 +167,9 @@ that are to be generated:
150167 end
151168 output_string # => "Foo,0\nBar,1\nBaz,2\n"
152169
153- ==== Generate to \String with Headers
170+ ==== Generate to \String
171+
172+ ===== Generate to \String with Headers
154173
155174\Class method CSV.generate can generate to a \String.
156175
@@ -163,7 +182,7 @@ that are to be generated:
163182 end
164183 output_string # => "Name,Value\nFoo,0\nBar,1\nBaz,2\n"
165184
166- ==== Generate to \File Without Headers
185+ ===== Generate to \File Without Headers
167186
168187\Class method CSV.open can generate to a \File.
169188
@@ -177,7 +196,9 @@ that are to be generated:
177196 end
178197 p File.read(path) # => "Foo,0\nBar,1\nBaz,2\n"
179198
180- ==== Generate to \File with Headers
199+ ==== Generate to \File
200+
201+ ===== Generate to \File with Headers
181202
182203\Class method CSV.open can generate to a \File.
183204
@@ -191,7 +212,9 @@ that are to be generated:
191212 end
192213 p File.read(path) # => "Name,Value\nFoo,0\nBar,1\nBaz,2\n"
193214
194- ==== Generate to \IO Stream Without Headers
215+ ==== Generate to \IO Stream
216+
217+ ===== Generate to \IO Stream Without Headers
195218
196219\Class method CSV.new can generate \CSV data to an \IO stream:
197220 path = 't.csv'
@@ -215,12 +238,14 @@ that are to be generated:
215238 end
216239 p File.read(path) # => "Name,Value\nFoo,0\nBar,1\nBaz,2\n"
217240
218- === Filtering
241+ === Filtering: Source and Output Formats
219242
220243\Class method CSV.filter provides a Unix-style filter for \CSV data.
221- The input \CSV data is processed to form output \CSV data.
244+ The source \CSV data is processed to form output \CSV data.
245+
246+ ==== Filter \String to \String
222247
223- ==== Filter \String to \String Without Headers
248+ ===== Filter \String to \String Without Headers
224249
225250 in_string = "foo,0\nbar,1\nbaz,2\n"
226251 out_string = ''
@@ -230,7 +255,7 @@ The input \CSV data is processed to form output \CSV data.
230255 end
231256 out_string # => "FOO,0000\nBAR,1111\nBAZ,2222\n"
232257
233- ==== Filter \String to \String with Headers
258+ ===== Filter \String to \String with Headers
234259
235260 in_string = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
236261 out_string = ''
@@ -240,7 +265,9 @@ The input \CSV data is processed to form output \CSV data.
240265 end
241266 out_string # => "Name,Value\nFOO,0000\nBAR,1111\nBAZ,2222\n"
242267
243- ==== Filter \String to \IO Stream Without Headers
268+ ==== Filter \String to \IO Stream
269+
270+ ===== Filter \String to \IO Stream Without Headers
244271
245272 in_string = "foo,0\nbar,1\nbaz,2\n"
246273 path = 't.csv'
@@ -252,7 +279,7 @@ The input \CSV data is processed to form output \CSV data.
252279 end
253280 p File.read(path) # => "FOO,0000\nBAR,1111\nBAZ,2222\n"
254281
255- ==== Filter \String to \IO Stream with Headers
282+ ===== Filter \String to \IO Stream with Headers
256283
257284 in_string = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
258285 path = 't.csv'
@@ -264,7 +291,9 @@ The input \CSV data is processed to form output \CSV data.
264291 end
265292 p File.read(path) # => "Name,Value\nFOO,0000\nBAR,1111\nBAZ,2222\n"
266293
267- ==== Filter \IO Stream to \String Without Headers
294+ ==== Filter \IO Stream to \String
295+
296+ ===== Filter \IO Stream to \String Without Headers
268297
269298 in_string = "foo,0\nbar,1\nbaz,2\n"
270299 path = 't.csv'
@@ -278,7 +307,7 @@ The input \CSV data is processed to form output \CSV data.
278307 end
279308 out_string # => "FOO,0000\nBAR,1111\nBAZ,2222\n"
280309
281- ==== Filter \IO Stream to \String with Headers
310+ ===== Filter \IO Stream to \String with Headers
282311
283312 in_string = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
284313 path = 't.csv'
@@ -292,7 +321,9 @@ The input \CSV data is processed to form output \CSV data.
292321 end
293322 out_string # => "Name,Value\nFOO,0000\nBAR,1111\nBAZ,2222\n"
294323
295- ==== Filter \IO Stream to \IO Stream Without Headers
324+ ==== Filter \IO Stream to \IO Stream
325+
326+ ===== Filter \IO Stream to \IO Stream Without Headers
296327
297328 in_path = 't.csv'
298329 in_string = "foo,0\nbar,1\nbaz,2\n"
@@ -308,7 +339,7 @@ The input \CSV data is processed to form output \CSV data.
308339 end
309340 p File.read(out_path) # => "FOO,0000\nBAR,1111\nBAZ,2222\n"
310341
311- ==== Filter \IO Stream to \IO Stream with Headers
342+ ===== Filter \IO Stream to \IO Stream with Headers
312343
313344 in_path = 't.csv'
314345 in_string = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
0 commit comments