Class: ActsAsTable::CSV::Writer

Inherits:
Writer
  • Object
show all
Defined in:
lib/acts_as_table/csv/writer.rb

Overview

ActsAsTable writer object for comma-separated values (CSV) format.

Instance Method Summary collapse

Constructor Details

#initialize(row_model, output = $stdout, **options) {|writer| ... } ⇒ ActsAsTable::CSV::Writer

Note:

Delegates output stream and options to constructor for +CSV+ object.

Returns a new ActsAsTable writer object for comma-separated values (CSV) format using the given ActsAsTable row model, output stream and options.

Parameters:

  • row_model (ActsAsTable::RowModel)
  • output (IO) (defaults to: $stdout)
  • options (Hash<Symbol, Object>)

Yield Parameters:

Yield Returns:

  • (void)

See Also:

  • CSV.new


17
18
19
20
21
22
23
24
25
26
# File 'lib/acts_as_table/csv/writer.rb', line 17

def initialize(row_model, output = $stdout, **options, &block)
  # @return [Hash<Symbol, Object>]
  csv_options = (options[:csv] || {}).merge({
    headers: false,
  })

  @csv = ::CSV.new(output, **csv_options)

  super(row_model, output, **options, &block)
end

Instance Method Details

#write_row(row) ⇒ ActsAsTable::Writer

Writes a row to the output stream.

Parameters:

  • row (Array<String, nil>, nil)

Returns:

  • (ActsAsTable::Writer)


32
33
34
35
36
# File 'lib/acts_as_table/csv/writer.rb', line 32

def write_row(row)
  @csv << row

  self
end