diff options
author | Burdette Lamar <[email protected]> | 2020-09-18 17:00:06 -0500 |
---|---|---|
committer | Sutou Kouhei <[email protected]> | 2020-11-24 09:33:55 +0900 |
commit | 98d52d873ef17414a83b3bc27f8d7e10163ccba2 (patch) | |
tree | c31abec0e4746abe62d18c4f13f71f80b2d37012 /doc/csv | |
parent | 8ea293b79c63d76443dd1fb352818c133302584d (diff) |
[ruby/csv] Organize page Recipes better (#176)
https://github.com/ruby/csv/commit/338b7f0d57
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3804
Diffstat (limited to 'doc/csv')
-rw-r--r-- | doc/csv/recipes.rdoc | 125 |
1 files changed, 78 insertions, 47 deletions
diff --git a/doc/csv/recipes.rdoc b/doc/csv/recipes.rdoc index eda18f6359..1ba3c44350 100644 --- a/doc/csv/recipes.rdoc +++ b/doc/csv/recipes.rdoc @@ -1,33 +1,46 @@ == Recipes === Contents -- {Parsing}[#label-Parsing] - - {Parse from String Without Headers}[#label-Parse+from+String+Without+Headers] - - {Parse from String with Headers}[#label-Parse+from+String+with+Headers] - - {Parse from File Without Headers}[#label-Parse+from+File+Without+Headers] - - {Parse from File with Headers}[#label-Parse+from+File+with+Headers] - - {Parse from IO Stream Without Headers}[#label-Parse+from+IO+Stream+Without+Headers] - - {Parse from IO Stream with Headers}[#label-Parse+from+IO+Stream+with+Headers] -- {Generating}[#label-Generating] - - {Generate to String Without Headers}[#label-Generate+to+String+Without+Headers] - - {Generate to String with Headers}[#label-Generate+to+String+with+Headers] - - {Generate to File Without Headers}[#label-Generate+to+File+Without+Headers] - - {Generate to File with Headers}[#label-Generate+to+File+with+Headers] - - {Generate to IO Stream Without Headers}[#label-Generate+to+IO+Stream+Without+Headers] - - {Generate to IO Stream with Headers}[#label-Generate+to+IO+Stream+with+Headers] -- {Filtering}[#label-Filtering] - - {Filter String to String Without Headers}[#label-Filter+String+to+String+Without+Headers] - - {Filter String to String with Headers}[#label-Filter+String+to+String+with+Headers] - - {Filter String to IO Stream Without Headers}[#label-Filter+String+to+IO+Stream+Without+Headers] - - {Filter String to IO Stream with Headers}[#label-Filter+String+to+IO+Stream+with+Headers] - - {Filter IO Stream to String Without Headers}[#label-Filter+IO+Stream+to+String+Without+Headers] - - {Filter IO Stream to String with Headers}[#label-Filter+IO+Stream+to+String+with+Headers] - - {Filter IO Stream to IO Stream Without Headers}[#label-Filter+IO+Stream+to+IO+Stream+Without+Headers] - - {Filter IO Stream to IO Stream with Headers}[#label-Filter+IO+Stream+to+IO+Stream+with+Headers] - -=== Parsing - -==== Parse from \String Without Headers + +- {Parsing: Source Formats}[#label-Parsing-3A+Source+Formats] + - {Parse from String}[#label-Parse+from+String] + - {Parse from String Without Headers}[#label-Parse+from+String+Without+Headers] + - {Parse from String with Headers}[#label-Parse+from+String+with+Headers] + - {Parse from File}[#label-Parse+from+File] + - {Parse from File Without Headers}[#label-Parse+from+File+Without+Headers] + - {Parse from File with Headers}[#label-Parse+from+File+with+Headers] + - {Parse from IO Stream}[#label-Parse+from+IO+Stream] + - {Parse from IO Stream Without Headers}[#label-Parse+from+IO+Stream+Without+Headers] + - {Parse from IO Stream with Headers}[#label-Parse+from+IO+Stream+with+Headers] +- {Generating: Output Formats}[#label-Generating-3A+Output+Formats] + - {Generate to String}[#label-Generate+to+String] + - {Generate to String Without Headers}[#label-Generate+to+String+Without+Headers] + - {Generate to String with Headers}[#label-Generate+to+String+with+Headers] + - {Generate to File}[#label-Generate+to+File] + - {Generate to File Without Headers}[#label-Generate+to+File+Without+Headers] + - {Generate to File with Headers}[#label-Generate+to+File+with+Headers] + - {Generate to IO Stream}[#label-Generate+to+IO+Stream] + - {Generate to IO Stream Without Headers}[#label-Generate+to+IO+Stream+Without+Headers] + - {Generate to IO Stream with Headers}[#label-Generate+to+IO+Stream+with+Headers] +- {Filtering: Source and Output Formats}[#label-Filtering-3A+Source+and+Output+Formats] + - {Filter String to String}[#label-Filter+String+to+String] + - {Filter String to String Without Headers}[#label-Filter+String+to+String+Without+Headers] + - {Filter String to String with Headers}[#label-Filter+String+to+String+with+Headers] + - {Filter String to IO Stream}[#label-Filter+String+to+IO+Stream] + - {Filter String to IO Stream Without Headers}[#label-Filter+String+to+IO+Stream+Without+Headers] + - {Filter String to IO Stream with Headers}[#label-Filter+String+to+IO+Stream+with+Headers] + - {Filter IO Stream to String}[#label-Filter+IO+Stream+to+String] + - {Filter IO Stream to String Without Headers}[#label-Filter+IO+Stream+to+String+Without+Headers] + - {Filter IO Stream to String with Headers}[#label-Filter+IO+Stream+to+String+with+Headers] + - {Filter IO Stream to IO Stream}[#label-Filter+IO+Stream+to+IO+Stream] + - {Filter IO Stream to IO Stream Without Headers}[#label-Filter+IO+Stream+to+IO+Stream+Without+Headers] + - {Filter IO Stream to IO Stream with Headers}[#label-Filter+IO+Stream+to+IO+Stream+with+Headers] + +=== Parsing: Source Formats + +==== Parse from \String + +===== Parse from \String Without Headers \Class method CSV.parse can read a source \String all at once, and so may have memory resource implications: @@ -43,7 +56,7 @@ Output: ["bar", "1"] ["baz", "2"] -==== Parse from \String with Headers +===== Parse from \String with Headers \Class method CSV.parse can read a source \String all at once, and so may have memory resource implications: @@ -59,7 +72,9 @@ Ouput: #<CSV::Row "Name":"bar" "Value":"1"> #<CSV::Row "Name":"baz" "Value":"2"> -==== Parse from \File Without Headers +==== Parse from \File + +===== Parse from \File Without Headers \Class method CSV.read can read a file all at once: string = "foo,0\nbar,1\nbaz,2\n" @@ -76,7 +91,7 @@ Output: ["bar", "1"] ["baz", "2"] -==== Parse from \File with Headers +===== Parse from \File with Headers Instance method CSV#read can reada file all at once: string = "Name,Value\nfoo,0\nbar,1\nbaz,2\n" @@ -93,7 +108,9 @@ Output: #<CSV::Row "Name":"bar" "Value":"1"> #<CSV::Row "Name":"baz" "Value":"2"> -==== Parse from \IO Stream Without Headers +==== Parse from \IO Stream + +===== Parse from \IO Stream Without Headers \Class method CSV.parse can read an \IO stream all at once: string = "foo,0\nbar,1\nbaz,2\n" @@ -114,7 +131,7 @@ Output: ["bar", "1"] ["baz", "2"] -==== Parse from \IO Stream with Headers +===== Parse from \IO Stream with Headers \Class method CSV.parse can read an \IO stream all at once: string = "Name,Value\nfoo,0\nbar,1\nbaz,2\n" @@ -135,7 +152,7 @@ Output: #<CSV::Row "Name":"bar" "Value":"1"> #<CSV::Row "Name":"baz" "Value":"2"> -=== Generating +=== Generating: Output Formats ==== Generate to \String Without Headers @@ -150,7 +167,9 @@ that are to be generated: end output_string # => "Foo,0\nBar,1\nBaz,2\n" -==== Generate to \String with Headers +==== Generate to \String + +===== Generate to \String with Headers \Class method CSV.generate can generate to a \String. @@ -163,7 +182,7 @@ that are to be generated: end output_string # => "Name,Value\nFoo,0\nBar,1\nBaz,2\n" -==== Generate to \File Without Headers +===== Generate to \File Without Headers \Class method CSV.open can generate to a \File. @@ -177,7 +196,9 @@ that are to be generated: end p File.read(path) # => "Foo,0\nBar,1\nBaz,2\n" -==== Generate to \File with Headers +==== Generate to \File + +===== Generate to \File with Headers \Class method CSV.open can generate to a \File. @@ -191,7 +212,9 @@ that are to be generated: end p File.read(path) # => "Name,Value\nFoo,0\nBar,1\nBaz,2\n" -==== Generate to \IO Stream Without Headers +==== Generate to \IO Stream + +===== Generate to \IO Stream Without Headers \Class method CSV.new can generate \CSV data to an \IO stream: path = 't.csv' @@ -215,12 +238,14 @@ that are to be generated: end p File.read(path) # => "Name,Value\nFoo,0\nBar,1\nBaz,2\n" -=== Filtering +=== Filtering: Source and Output Formats \Class method CSV.filter provides a Unix-style filter for \CSV data. -The input \CSV data is processed to form output \CSV data. +The source \CSV data is processed to form output \CSV data. + +==== Filter \String to \String -==== Filter \String to \String Without Headers +===== Filter \String to \String Without Headers in_string = "foo,0\nbar,1\nbaz,2\n" out_string = '' @@ -230,7 +255,7 @@ The input \CSV data is processed to form output \CSV data. end out_string # => "FOO,0000\nBAR,1111\nBAZ,2222\n" -==== Filter \String to \String with Headers +===== Filter \String to \String with Headers in_string = "Name,Value\nfoo,0\nbar,1\nbaz,2\n" out_string = '' @@ -240,7 +265,9 @@ The input \CSV data is processed to form output \CSV data. end out_string # => "Name,Value\nFOO,0000\nBAR,1111\nBAZ,2222\n" -==== Filter \String to \IO Stream Without Headers +==== Filter \String to \IO Stream + +===== Filter \String to \IO Stream Without Headers in_string = "foo,0\nbar,1\nbaz,2\n" path = 't.csv' @@ -252,7 +279,7 @@ The input \CSV data is processed to form output \CSV data. end p File.read(path) # => "FOO,0000\nBAR,1111\nBAZ,2222\n" -==== Filter \String to \IO Stream with Headers +===== Filter \String to \IO Stream with Headers in_string = "Name,Value\nfoo,0\nbar,1\nbaz,2\n" path = 't.csv' @@ -264,7 +291,9 @@ The input \CSV data is processed to form output \CSV data. end p File.read(path) # => "Name,Value\nFOO,0000\nBAR,1111\nBAZ,2222\n" -==== Filter \IO Stream to \String Without Headers +==== Filter \IO Stream to \String + +===== Filter \IO Stream to \String Without Headers in_string = "foo,0\nbar,1\nbaz,2\n" path = 't.csv' @@ -278,7 +307,7 @@ The input \CSV data is processed to form output \CSV data. end out_string # => "FOO,0000\nBAR,1111\nBAZ,2222\n" -==== Filter \IO Stream to \String with Headers +===== Filter \IO Stream to \String with Headers in_string = "Name,Value\nfoo,0\nbar,1\nbaz,2\n" path = 't.csv' @@ -292,7 +321,9 @@ The input \CSV data is processed to form output \CSV data. end out_string # => "Name,Value\nFOO,0000\nBAR,1111\nBAZ,2222\n" -==== Filter \IO Stream to \IO Stream Without Headers +==== Filter \IO Stream to \IO Stream + +===== Filter \IO Stream to \IO Stream Without Headers in_path = 't.csv' in_string = "foo,0\nbar,1\nbaz,2\n" @@ -308,7 +339,7 @@ The input \CSV data is processed to form output \CSV data. end p File.read(out_path) # => "FOO,0000\nBAR,1111\nBAZ,2222\n" -==== Filter \IO Stream to \IO Stream with Headers +===== Filter \IO Stream to \IO Stream with Headers in_path = 't.csv' in_string = "Name,Value\nfoo,0\nbar,1\nbaz,2\n" |