Class: VFCSV::Writer
- Inherits:
-
Object
- Object
- VFCSV::Writer
- Defined in:
- lib/vfcsv.rb
Overview
Writer for streaming CSV to files
Instance Method Summary collapse
- #<<(row) ⇒ Object (also: #add_row, #puts)
- #close ⇒ Object
-
#initialize(path, mode, options) ⇒ Writer
constructor
A new instance of Writer.
Constructor Details
#initialize(path, mode, options) ⇒ Writer
Returns a new instance of Writer.
500 501 502 503 504 505 506 507 |
# File 'lib/vfcsv.rb', line 500 def initialize(path, mode, ) @file = File.open(path, mode) @options = VFCSV::DEFAULT_OPTIONS.merge() @col_sep = @options[:col_sep] || "," @quote_char = @options[:quote_char] || '"' @force_quotes = @options[:force_quotes] || false @quote_empty = @options.fetch(:quote_empty, true) end |
Instance Method Details
#<<(row) ⇒ Object Also known as: add_row, puts
509 510 511 512 513 514 515 516 517 |
# File 'lib/vfcsv.rb', line 509 def <<(row) @file.write(Generator.generate_line(row, col_sep: @col_sep, quote_char: @quote_char, force_quotes: @force_quotes, quote_empty: @quote_empty )) self end |
#close ⇒ Object
521 522 523 |
# File 'lib/vfcsv.rb', line 521 def close @file.close end |