The project is in a healthy, maintained state
ActsAsTable extension for parsing/serializing CSV data.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
 Project Readme

CSV Support for ActsAsTable

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

Documentation

  • {ActsAsTable::CSV}
    • {ActsAsTable::CSV::Reader}
    • {ActsAsTable::CSV::Writer}

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 {file:LICENSE} file.