CSV Support for ActsAsTable

This is an ActsAsTable extension that adds support for parsing/serializing Comma-Separated Values (CSV) data.

Documentation

Dependencies

Installation

The recommended installation method is via RubyGems. To install the latest, official release of the ActsAsTable::CSV gem, do:

% [sudo] gem install acts_as_table_csv

Examples

require 'acts_as_table'

Writing CSV data

# @return [ActsAsTable::RowModel]
@row_model = ...

# @return [Array<ActiveRecord::Base>]
@bases = ...

ActsAsTable.for(:csv).writer(@row_model, $stdout) do |writer|
  @bases.each do |base|
    writer << base
  end
end

Reading CSV data

# @return [ActsAsTable::RowModel]
@row_model = ...

# @return [ActsAsTable::Table]
@table = @row_model.tables.new

ActsAsTable.for(:csv).reader(@row_model, $stdin) do |reader|
  reader.each_row do |row|
    # @return [Array<ActsAsTable::Record>]
    records = @table.from_row(row)

    records.each do |record|
      record.position = reader.lineno
    end
  end
end

Author

License

This software is licensed under a 3-clause BSD license.

For more information, see the accompanying LICENSE file.