Module: Philiprehberger::CsvBuilder
- Defined in:
- lib/philiprehberger/csv_builder.rb,
lib/philiprehberger/csv_builder/column.rb,
lib/philiprehberger/csv_builder/builder.rb,
lib/philiprehberger/csv_builder/version.rb
Defined Under Namespace
Classes: Builder, Column, Error, ValidationError
Constant Summary collapse
- VERSION =
'0.8.0'
Class Method Summary collapse
-
.build(records, delimiter: ',', quote_char: '"', row_sep: "\n", bom: false, encoding: 'UTF-8', empty_value: '') {|builder| ... } ⇒ Builder
Build a CSV from records using a declarative DSL.
-
.psv(records, **options) {|builder| ... } ⇒ Builder
Shorthand for pipe-separated output.
-
.tsv(records, **options) {|builder| ... } ⇒ Builder
Shorthand for tab-separated output.
Class Method Details
.build(records, delimiter: ',', quote_char: '"', row_sep: "\n", bom: false, encoding: 'UTF-8', empty_value: '') {|builder| ... } ⇒ Builder
Build a CSV from records using a declarative DSL
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/philiprehberger/csv_builder.rb', line 25 def self.build(records, delimiter: ',', quote_char: '"', row_sep: "\n", bom: false, encoding: 'UTF-8', empty_value: '', &block) raise Error, 'A block is required' unless block builder = Builder.new( records, delimiter: delimiter, quote_char: quote_char, row_sep: row_sep, bom: bom, encoding: encoding, empty_value: empty_value ) builder.instance_eval(&block) builder end |
.psv(records, **options) {|builder| ... } ⇒ Builder
Shorthand for pipe-separated output
54 55 56 |
# File 'lib/philiprehberger/csv_builder.rb', line 54 def self.psv(records, **, &) build(records, **, delimiter: '|', &) end |
.tsv(records, **options) {|builder| ... } ⇒ Builder
Shorthand for tab-separated output
44 45 46 |
# File 'lib/philiprehberger/csv_builder.rb', line 44 def self.tsv(records, **, &) build(records, **, delimiter: "\t", &) end |