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.6.0'
Class Method Summary collapse
-
.build(records, delimiter: ',', quote_char: '"', bom: false, encoding: 'UTF-8') {|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: '"', bom: false, encoding: 'UTF-8') {|builder| ... } ⇒ Builder
Build a CSV from records using a declarative DSL
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/philiprehberger/csv_builder.rb', line 23 def self.build(records, delimiter: ',', quote_char: '"', bom: false, encoding: 'UTF-8', &block) raise Error, 'A block is required' unless block builder = Builder.new( records, delimiter: delimiter, quote_char: quote_char, bom: bom, encoding: encoding ) builder.instance_eval(&block) builder end |
.psv(records, **options) {|builder| ... } ⇒ Builder
Shorthand for pipe-separated output
51 52 53 |
# File 'lib/philiprehberger/csv_builder.rb', line 51 def self.psv(records, **, &) build(records, **, delimiter: '|', &) end |
.tsv(records, **options) {|builder| ... } ⇒ Builder
Shorthand for tab-separated output
41 42 43 |
# File 'lib/philiprehberger/csv_builder.rb', line 41 def self.tsv(records, **, &) build(records, **, delimiter: "\t", &) end |